Passwordless access to MySQL by using sudo
Tired of remembering root passwords for MySQL on your servers? Fear no more, help is on the way.
I’ll assume that you have a Linux system set up with sudo and mysql already installed. Fire up a terminal and type
sudo su
Open up ~/.my.cnf in your favorite editor (the ~ points to the root account now).
vim ~/.my.cnf
and add the following contents:
[client]
user = root
password = yourpassword
Follow up with logging out of root:
exit
And run sudo to start MySQL. Remember to use the -H option to point all requests for ~ to root’s home directory:
sudo -H mysql
It is a simple as that :)