意外的mysql -urootauthentication

所以,unix root用户可以不用密码连接到mysql root用户:

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) 

但是unix用户redmine不能:

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

我猜mysqld通过连接的unix域套接字检查uid = 1,但我不能看到这是在mysql文档中解释。 (strace显示mysql shell进程成功打开unix域套接字并在从服务器获得回复后closures它)

如何作为非root用户unix连接到没有密码的数据库root用户? (请把我的“这不是一个好主意”一行)

也许root用户有一个包含login凭证的/root/.my.cnf文件? 你可以configuration~redmine/.my.cnf来包含你的凭证:

 [client] password="yourpassword" 

有关更多信息,请参阅MySQL文档 。