I have an Ubuntu server with MySQL.

On the command line, this works

  mysqldump -u root -p paydaydebt

(then I have to manually type the password)

On the command line, these do not work:

mysqldump -u root -p{password} paydaydebt 
mysqldump -u root --password={password} paydaydebt

Is there any way I can enter the password with -p or --password?

link|improve this question

feedback

4 Answers

up vote 5 down vote accepted

You should not. Given the password at the command line is evil as it is visible to everybody issuing a ps or top.

The recommended way is to specify the password in a separate file and then add a command line switch --defaults-extra-file=/etc/mysql/mysqlpassword.cnf

The mysqlpassword.cnf then contains (only):

[mysqldump]
# The following password will be sent to mysqldump 
password="ThisIsThePassword"

Make sure that this file is only readable for the user executing mysqldump (preferable root).

link|improve this answer
feedback

Don't leave a space between the -p and the password that you are passing to mysqldump. If you do put a space in the password will be interpreted as the name of a database to act upon.

mysqldump -uroot -pPassword dbase

would dump database dbase

mysqldump -uroot -p Password dbase

would ask for a password and try to dump the database Password.

However as mailq says you should probably avoid the use of the password on the command line.

link|improve this answer
feedback

If your password including special characters, you must escape with a backslash.

link|improve this answer
feedback

What's your mysql version? Normally, the following syntax should work just fine:

mysqldump -uroot -p'ThisIsThePassword' mysql

Include the password in between ' 's to avoid special chars being parsed by the shell or otherwise escape them.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.