Take the 2-minute tour ×

I have a /root/.my.cnf file which stores the mysql root user's password:

password = "my password"

When I log in as system root and enter mysql, I get a passwordless login:

myuser@local:$ sudo su
root@local:$ mysql

But when I try to do the same just using sudo, I get access denied:

myuser@local:$ sudo mysql

How can I get sudo mysql to log me in as the mysql root user, without entering a password?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

sudo -i mysql should also work - That should run mysql under a fresh interactive shell.

share|improve this answer

The command sudo su -c "mysql" will have the desired effect.

share|improve this answer

Your Answer


