MySQL mysqldump --password 真的按照它说的做吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/148951/
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
Does mysqldump --password really do what it says?
提问by John Zwinck
I'm trying to use mysqldump
to dump a schema, and it mostly works but I ran into one curiosity: the -p
or --password
option seems like it is doing something other than setting the password (as the man
page and --help
output say it should).
我正在尝试使用mysqldump
转储模式,并且它大多有效,但我遇到了一个好奇心:-p
or--password
选项似乎正在执行除设置密码之外的其他操作(正如man
页面和--help
输出所说的那样)。
Specifically, it looks like it's doing what is indicated here: http://snippets.dzone.com/posts/show/360- that is, setting the database to dump.
具体来说,它看起来像是在执行此处指示的操作:http: //snippets.dzone.com/posts/show/360- 也就是说,将数据库设置为转储。
To support my somewhat outlandish claim, I can tell you that if I do not specify the --password
(or -p
) option, the command prints the usage statement and exits with an error. If I do specify it, I am immediately prompted to enter a password (!), and then the database specified in the --password
option is dumped (or an error is given in the usual case that a password not matching any database name was specified).
为了支持我有点古怪的说法,我可以告诉您,如果我不指定--password
(or -p
) 选项,该命令将打印使用语句并以错误退出。如果我确实指定了它,我会立即提示输入密码 (!),然后在--password
选项中指定的数据库被转储(或者在通常情况下给出一个错误,即指定的密码与任何数据库名称都不匹配)。
Here's a transcript:
这是一个成绩单:
$ mysqldump -u test -h myhost --no-data --tables --password lose Enter password: -- MySQL dump 10.10 mysqldump: Got error: 1044: Access denied for user 'test'@'%' to database 'lose' when selecting the database
So, what gives? Is this the way this is supposed to work? It surely does not appear to make sense nor does it match the official documentation. And finally, if this just the way it works, how am I meant to specify the password to be used in an automated job? Using expect
???
那么,什么给?这是应该的工作方式吗?它肯定没有任何意义,也不符合官方文档。最后,如果这只是它的工作方式,我打算如何指定要在自动化作业中使用的密码?使用expect
???
I'm using mysqldump Ver 10.10 Distrib 5.0.22, for pc-linux-gnu (i486)
.
我正在使用mysqldump Ver 10.10 Distrib 5.0.22, for pc-linux-gnu (i486)
.
回答by antik
From man mysqldump:
来自 man mysqldump:
--password[=password], -p[password]
The password to use when connecting to the server. If you use the short option form (-p), you cannot have a space between the option and the password. If you omit the password value following the --password or -p option on the command line, you are prompted for one.
Specifying a password on the command line should be considered insecure. See Section 6.6, "Keeping Your Password Secure".
--password[=password], -p[password]
连接到服务器时使用的密码。如果使用短选项形式 (-p),则选项和密码之间不能有空格。如果您省略命令行上 --password 或 -p 选项后面的密码值,系统会提示您输入密码。
在命令行上指定密码应该被认为是不安全的。请参阅第 6.6 节“保持密码安全”。
Syntactically, you are not using the --password switch correctly. As such, the command line parser is seeing your use of "lose" as a stand-alone argument which mysqldump interprets as the database name as it would if you were to attempt a simpler command like mysqldump lose
从语法上讲,您没有正确使用 --password 开关。因此,命令行解析器将您使用“lose”作为独立参数,mysqldump 将其解释为数据库名称,就像您尝试使用更简单的命令一样mysqldump lose
To correct this, try using --password=lose
or -plose
or simply use -p
or --password
and type the password when prompted.
要更正此问题,请尝试使用--password=lose
or-plose
或简单地使用-p
or--password
并在出现提示时键入密码。
回答by Mark Biek
Another option is to create the file ~/.my.cnf(permissions need to be 600).
另一种选择是创建文件~/.my.cnf(权限需要为 600)。
Add this to the .my.cnf file
将此添加到 .my.cnf 文件
[client]
password=lose
This lets you connect as a MySQL user who requires a password without having to actually enter the password. You don't even need the -p or --password.
这使您可以作为需要密码的 MySQL 用户进行连接,而无需实际输入密码。您甚至不需要 -p 或 --password。
Very handy for scripting mysql & mysqldump commands.
对于编写 mysql 和 mysqldump 命令的脚本非常方便。
回答by Phil Gordemer
I found that this happens if your password has special characters in it. The mysql password here has a ! in it, so I have to do ==password='xxx!xxxx' for it to work corrrectly. Note the ' marks.
我发现如果您的密码中包含特殊字符,就会发生这种情况。这里的mysql密码有一个!在里面,所以我必须做 ==password='xxx!xxxx' 才能正常工作。注意 ' 标记。
回答by Steve Baker
Try placing a '=' in between --password lose like:
尝试在 --password loss 之间放置一个“=”,例如:
--password=lose
If you use -p, then there can be no space between the -p and the password, i.e. '-plose'.
如果使用 -p,则 -p 和密码之间不能有空格,即“-plose”。
回答by nathan
I am not sure if it works for the --password version, but if you use -p you can specify the password immediately afterwards (the key is not to include a space):
我不确定它是否适用于 --password 版本,但是如果您使用 -p 您可以在之后立即指定密码(关键是不要包含空格):
mysqldump -pmypassword ...
mysqldump -pmypassword ...
回答by itsmatt
Did you try --password=whatever-password-is ?
你试过 --password=whatever-password-is 吗?
Perhaps I'm missing the question, but that is what I do to run the tool.
也许我错过了这个问题,但这就是我运行该工具所做的工作。
回答by Giuseppe Maxia
If you use the -p or --password without an argument, you will get a prompt, asking to insert a password.
如果您使用不带参数的 -p 或 --password,您将收到提示,要求输入密码。
If you want to indicate a password on the command line, you must use -pYOURPASSWORD or --password=YOURPASSWORD. Notice that there is no space after -p, and there is an "=" sign after --password.
如果要在命令行中指定密码,则必须使用 -pYOURPASSWORD 或 --password=YOURPASSWORD。注意 -p 后没有空格,--password 后有一个“=”符号。
In your example, mysqldump asks for a password, and then treats "lose" as the database name. If that was your password, you should have included a "="
在您的示例中,mysqldump 要求输入密码,然后将“丢失”视为数据库名称。如果这是您的密码,您应该包含一个“=”
回答by Patrick Desjardins
回答by Justin Bennett
The -p option does not require an argument. You just put -p or --password to indicate that you're going to use a password to access the database. The reason it's dumping the database named whatever you put after -p is that the last argument for mysqldump should be the name of the database you want to dump (or --all-databases if you want them all).
-p 选项不需要参数。您只需输入 -p 或 --password 来指示您将使用密码来访问数据库。它转储数据库的原因是您在 -p 之后放置的任何名称是 mysqldump 的最后一个参数应该是您想要转储的数据库的名称(或者 --all-databases 如果您想要所有这些)。
@Nathan's answer is also true. You can specify the password immediatelyfollowing the -p switch (useful in scripts and such where you can't enter it by hand after executing the command).
@Nathan 的回答也是如此。您可以在 -p 开关后立即指定密码(在脚本中很有用,以及在执行命令后无法手动输入的情况)。
回答by Giuda
Maybe your user "test" doesn't have the permission to access your "lose" database?
也许您的用户“test”无权访问您的“丢失”数据库?