sajad torkamani

What is mysql_config_editor?

mysql_config_editor is a MySQL tool can stores your authentication credentials in an obfuscated config file, allowing you to use MySQL client programs (e.g., mysqldump) without having to provide credentials each time.

How to use it

Create a ~/.mylogin.cnf file containing your database credentials by running the following:

mysql_config_editor set --login-path=client --host=<your-host> --user=<your-user> --password

Assuming the user root and the host localhost, we can run:

mysql_config_editor set --login-path=client --host=localhost --user=root --password

Enter password when prompted.

Client programs like mysql and mysqldump automatically check if a ~/.mylogin.cnf exists. If you create one, you’ll be able to use these programs without needing to provide the username and password each time.

# Note how no -u or -p options are passed
mysqldump <database> > <dump_file>

Passwordless authentication becomes very useful when automating MySQL-related tasks like database back ups.

Sources