我已经在Ubuntu 18.04 LTS上从apt安装了MySQL 5.7.27。它带有一个空的root密码,因此我使用以下命令登录CLI:
mysql -uroot -p
然后在提示输入密码时按Enter。然后,我使用以下命令更改了root密码:
set password for 'root'@'localhost'=PASSWORD('newPass');
flush privileges;
(我认为不必具有冲洗权限,而只是为了皮带和牙套)。
现在,我可以使用mysql -uroot -pnewPass
登录到CLI,它可以连接OK。一切都很好。
但是我仍然可以使用空白密码登录!!似乎也接受。
那么,如何删除空白密码?
如果这只是MySQL中的一个安全漏洞,这似乎很疯狂。
更多信息:MySQL user
表具有此功能:
mysql> select host, user, authentication_string from user;
+-----------+--------------------+-------------------------------------------+
| host | user | authentication_string |
+-----------+--------------------+-------------------------------------------+
| localhost | root | |
| localhost | mysql.session | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| localhost | mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| localhost | debian-sys-maint | *[valid hash removed for security] |
| localhost | another-user | *[valid hash removed for security] |
+-----------+--------------------+-------------------------------------------+
...显然很有趣,因为root用户根本没有身份验证字符串。我认为也许我可以发出一个update user set authentication_string=PASSWORD('aaa')
之类的命令,它就可以工作-但看起来很黑。对我来说set password for
绝对应该做点什么。