mysql_config_editor

This utility enables you to store authentication credentials in an obfuscated login path file named ~/.mylogin.cnf. 

On Windows the file is in %APPDATA%\MySQL

This is useful for connecting to the database securely from within scripts etc.

Check

To see the contents of mylogin.cnf...

Password is obfuscated in the output from this command

mysql_config_editor print --all

Create

mysql_config_editor set --user=root --password

This will create an entry under the default [client] login-path

To use the stored password...

mysql

Note that, when storing the root password in this way, MySQL is only as secure as your OS login (i.e. if your OS account is breached, then the database is too).

login-path

To store a password that could be used by a scheduled mysqlbackup...

mysql_config_editor set --login-path=mysqlbackup --host=myserver --user=mysqlbackup --password

You will be prompted for the passwordlogin_path is an arbitrary label that you will pass when you later try to connecthost and user must match with an existing MySQL userNote that login-paths of 'mysql' and 'client' are special cases that are always read when trying to connect irrespective of whether you pass log-path when connecting.

To use the stored password...

mysql --login-path=mysqlbackup

mysqlbackup --login-path=mysqlbackup --backup-dir=/mysql/backup/FULL --socket=/mysql/mysql.sock --compress backup

Delete

To delete an entry...

mysql_config_editor delete --login-path=mysqlbackup

To clear all entries...

mysql_config_editor reset

Bibliography