MySQL mysqldump 问题:“--defaults-extra-file”选项未按预期工作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3836214/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Problem with mysqldump: "--defaults-extra-file" option is not working as expected
提问by Misha Moroshko
I run the following command from the Windows command line to backup my database:
我从 Windows 命令行运行以下命令来备份我的数据库:
...\right_path\mysqldump --add-drop-database --databases my_database_name
--defaults-extra-file=d:.cnf
where d:\1.cnf
contains the following:
其中d:\1.cnf
包含以下内容:
[client]
user="my_user"
password="my_password"
Unfortunately, I got the following error message:
不幸的是,我收到以下错误消息:
mysqldump: unknown variable 'defaults-extra-file=d:.cnf'
If I do:
如果我做:
...\right_path\mysqldump --add-drop-database --databases my_database_name
--user="my_user" --password="my_password"
it works as expected.
它按预期工作。
What am I doing wrong ?
我究竟做错了什么 ?
回答by Misha Moroshko
I found the answer: --defaults-extra-file
must be the first option. This works as expected:
我找到了答案:--defaults-extra-file
必须是第一选择。这按预期工作:
...\right_path\mysqldump --defaults-extra-file=d:.cnf
--add-drop-database --databases my_database_name
回答by Peter K.
I realize this is Linux-specific, but my searches brought me here.
我意识到这是特定于 Linux 的,但我的搜索将我带到了这里。
I'm using bitnami's LAMP stack, and found out that their "mysqldump" is actually a script:
我正在使用 bitnami 的 LAMP 堆栈,并发现他们的“mysqldump”实际上是一个脚本:
LD_LIBRARY_PATH=/opt/lampstack-5.5.3-0/mysql/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH
case "$@" in
*--no-defaults*)
exec ##代码##.bin "$@"
exit
esac
exec ##代码##.bin --defaults-file=/opt/lampstack-5.5.3-0/mysql/my.cnf "$@"
which doesn't appear to allow --defaults-file
to be passed in... and work (as per the accepted answer here).
这似乎不允许--defaults-file
传入......并工作(根据此处接受的答案)。
回答by cynkiller
Also meet this problem. Found there's another situation that would cause --defaults-extra-file
option not recognized.
也遇到这个问题。发现还有另一种情况会导致--defaults-extra-file
选项无法识别。
When you changed IFS in script, it's possible to hit this problem. The solution is to reset IFS before execute mysql statement.
当您在脚本中更改 IFS 时,可能会遇到此问题。解决方法是在执行mysql语句之前重置IFS。
For reference.
以供参考。