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:

This is particularly useful for automation of routine backups etc.

mysql_config_editor

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

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:

To remove a stored login use:

.mylogin.cnf

mysqldump

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.

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

 

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 class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">