我正在设置一个 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)
我认为这不应该允许 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)