Password-less Login to the MySQL Command Line

The goal here was to be able to log in to the MySQL command prompt be simply typing


rather than:

mysql -u root -p

This is particularly useful for automation of routine backups etc.


The command mysql_config_editor has several options (e.g. add, remove, print) for managing encrypted passwords. To create a new login

mysql_config_editor set --user=root --password

It is also possible to use the option –login-path=myinstancename to configure multiple sign-ins but omitting that option (as above) sets the default.

After running the command above you will be prompted for the user password and after supplying it the encrypted details are stored in ~/.mylogin.cnf

To print details of your created logins use:

mysql_config_editor print

To remove a stored login use:

mysql_config_editor remove



After creating the .mylogin.cnf file typing ‘mysql’ or ‘mysqldump’ at the command line will automatically use the .mylogin.cnf file and will not prompt for a password. So no need to store the MySQL password in plain text.

What happens if you change the root password?

If you change the root password e.g.

mysqladmin -u root -p password

You would need to recreate the .mylogin.cnf i.e.

mysql_config_editor remove
mysql_config_editor set --user=root --password


Leave a Reply

  • (will not be published)

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>