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

MySQL

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?

Best Answer

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