# How to use mysqldump without password prompt

In order to use mysqldump without being asked for a password, you have to create a file ~/.my.cnf with permissions 600. Add the following lines to the file:

[mysqldump]
user=mysqluser
password=secret

After that, you can use the mysqldump command and the password will be taken from the ~/.my.cnf file.

mysqldump my_app > my_backup.sql

WARNING

In order to use the password from the ~/.my.cnf file, you must NOT use the -p argument when running the mysqldump command.

# Using a custom path for the file

If you want to store the file in a different location, you can specify the path using the --defaults-file flag. Example:

mysqldump --defaults-file=/path-to/.my.cnf my_app > my_backup.sql

WARNING

The flag --defaults-file must be the first argument given to mysqldump.