Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 7 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):

# The following password will be sent to mysqldump 

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

In addition to mailqs answer: --defaults-extra-file=/etc/mysql/mysqlpassword.cnf must be the first option in the command. Example:

mysqldump --defaults-extra-file=/etc/mysql/mysqlpassword.cnf -u root paydaydebt
share|improve this answer

Your Answer


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.