Over a million developers have joined DZone.

Passwordless Command Line Scripts with MySQL 5.6

· Big Data Zone

Hortonworks DataFlow is an integrated platform that makes data ingestion fast, easy, and secure. Download the white paper now.  Brought to you in partnership with Hortonworks

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}

Hortonworks Sandbox is a personal, portable Apache Hadoop® environment that comes with dozens of interactive Hadoop and it's ecosystem tutorials and the most exciting developments from the latest HDP distribution, brought to you in partnership with Hortonworks.


Published at DZone with permission of Rob Allen, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}