Run mysql without using a password
Sometimes when running a script as root, you need to execute a mysql command.
To get around the problem created by the password – execute the following command one time:
mysql_config_editor set --login-path=client --host=localhost --user=root --password
Fill in the password when prompted and a file named /root/.mylogin.cnf will be created with the password encrypted.
Note: if your password has ‘#’ in it, and possibly other characters, use single quotes when entering the password.
Applies to MySQL 5.6.6 and higher