Mysql – How to Dump all databases from MySql server with thesqldump without passwords

database-backupMySQL

Is it possible to dump all databases without supplying the username and password for each databe ? The server has 10 databases with different usernames and passwords.

I will be logged in as root (centOS)

I used the following but i get access errors

mysqldump --all-databases > gzip > bak-sql.zip

[fixed]

mysqldump -u admin --password='password' --all-databases | gzip -7 > bak-sql.zip

[Related Thread]

https://stackoverflow.com/questions/8444108/how-to-use-mysql-dump

Best Answer

Try this (from the mysql documentation):

first create a config file for mysql and make sure that only your account has access to it:

touch ~/.my.cnf
chmod 600 ~/.my.cnf

add the username password combinations in the config file:

[mysqldump]
user=databseuser12
password=otFRD?17*<8X0G

You can then run the mysqldump command without a password:

mysqldump --user=databseuser12 --host=mysql.example.com forumsalpha | gzip -9 > /home/myuser/backups/dbs/mysql-forumsalpha.sql.gz