Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

4 Answers 4

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).

share|improve this answer

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.

share|improve this answer

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

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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