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 🙂

Published by

Svenn-Arne Dragly

I'm a physicist and programmer, writing about the stuff I figure out as I go.

3 thoughts on “Passwordless access to MySQL by using sudo”

Leave a Reply