Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Passwordless Command Line Scripts with MySQL 5.6

DZone's Guide to

Passwordless Command Line Scripts with MySQL 5.6

· Big Data Zone ·
Free Resource

Hortonworks Sandbox for HDP and HDF is your chance to get started on learning, developing, testing and trying out new features. Each download comes preconfigured with interactive tutorials, sample data and developments from the Apache community.

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 for HDP and HDF is your chance to get started on learning, developing, testing and trying out new features. Each download comes preconfigured with interactive tutorials, sample data and developments from the Apache community.

Topics:

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}