So, unix root user can connect to mysql root user without password:

root@server $ mysql -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 27
Server version: 5.7.13-0ubuntu0.16.04.2 (Ubuntu)

But unix user redmine can't:

root@server $ sudo -u redmine mysql -uroot
ERROR 1698 (28000): Access denied for user 'root'@'localhost'

I guess that mysqld is checking uid=1 over the connecting unix domain socket but I can't see where this is explained in the mysql docs. (strace shows the mysql shell process opening the unix domain socket successfully and closing it after getting a reply from the server)

How do I connect to the database root user without password as a non-root unix user ? (please, spare me the "it's not a good idea" line)

  • FYI, it appears there is no way to keep the root user without a password and connect to it with a non-root unix user. – mathieu Aug 25 '16 at 12:08

Maybe the root user has a /root/.my.cnf file which contains the login credentials? You can configure ~redmine/.my.cnf to contain your credentials:


For more, see the MySQL documentation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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