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

[client]
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
mysql>

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

myuser@local:$ sudo mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

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

link|improve this question

80% accept rate
feedback

2 Answers

up vote 2 down vote accepted

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

link|improve this answer
feedback

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

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.