尽管设置了密码,但MySQL允许无密码连接

Mar*_*niz 8 mysql passwords

我正在设置MySQL服务器(实际上是Percona服务器,但这无关紧要)我正在为root用户设置密码.最后,我有这个:

mysql> select host, user, password from user;
+-----------+------------------+-------------------------------------------+
| host      | user             | password                                  |
+-----------+------------------+-------------------------------------------+
| localhost | root             | *huge string here, no kidding             |
| localhost | debian-sys-maint | *another huge string here                 |
+-----------+------------------+-------------------------------------------+
2 rows in set (0.00 sec)
Run Code Online (Sandbox Code Playgroud)

我认为这不应该允许root用户在没有密码的情况下连接.但是,如果我转到命令行,我可以连接mysql -u root或只是mysql.如果我这样做mysql -u root -p并点击输入密码,那么我得到ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO).

任何人都可以向我解释如何确保用户只能连接密码?

编辑:如果相关,我设置密码 SET PASSWORD FOR 'root'@'localhost' = PASSWORD('somethinghere');

编辑:输出show grants,它表示我使用密码登录但我没有.

mysql> show grants;
+----------------------------------------------------------------------------------------------------------------------------------------+
| Grants for root@localhost                                                                                                              |
+----------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*huge string here, no kidding' WITH GRANT OPTION |
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION                                                                           |
+----------------------------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
Run Code Online (Sandbox Code Playgroud)

Mar*_*niz 12

捂脸.原来在/ root上有一个带有用户名和密码的.my.cnf,因此只能mysql在使用root帐户时登录(这就是我使用的).它是由Chef配方创建的(percona是通过Chef安装的),我不知道它.

提示是要查看输出show grants.即使我没有输入密码,它仍然说我输了一个,所以必须有一个地方!