Mysql_dump without password prompt

Sometimes you want to make a database dump without providing the password.

Providing it in the command is a security issue if the history is recorded.

Hence, the user that does the command should have this file in his home directory:

~/.my.cnf

[mysqldump]
user=mysqluser
password=secret

This only works if this file has permissions 600:

$ chmod 600 ~/.my.cnf

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.

Now if you also want to be able to restore a database wihout prompting for the password, add these lines to ~/.my.cnf:

[client]
user=mysqluser
password=password