Pragmatism in the real world

Password less command line scripts with MySQL 5.6

I have a number of command line scripts that copy MySQL databases down from staging servers and store them locally. These scripts set the password on the command line using the -p option.

With MySQL 5.6, a new warning is displayed every time my scripts run:

Warning: Using a password on the command line interface can be insecure.

This is annoying!

The way to solve this is to use the new command line tool mysql_config_editor to set up a “login path” which the mysql command line client can then use.

$ mysql_config_editor set --login-path=restore --host=localhost --user=restore --password

You will then be asked to enter the password for the user that you’ve set, ‘restore’ in this case.

Now, you can log in to mysql on the command line using:

$ mysql --login-path=restore

and note that you didn’t need to enter a password!

In my case, I then changed my scripts so that the restore line looks like this:

cat ${FILENAME} | mysql --login-path=restore ${DBNAME}

One thought on “Password less command line scripts with MySQL 5.6

Comments are closed.