如何检查mysql中是否设置了用户密码?

ana*_*nik 0 mysql authentication

我需要对新服务器运行自动检查.其中一项检查是检测是否设置了用户(或root)密码.但..

mysql> SELECT host, user, password FROM mysql.user;
ERROR 1054 (42S22): Unknown column 'password' in 'field list'
Run Code Online (Sandbox Code Playgroud)

服务器版本:5.7.18-0ubuntu0.17.04.1(Ubuntu)

Ray*_*and 6

MySQL版本5.7或更高版本在mysql.user表中没有名为password的列.MySQL 5.7或更高版本使用列authentication_string代替.

所以你的查询应该是:

SELECT host, user, authentication_string FROM mysql.user
Run Code Online (Sandbox Code Playgroud)

  • (注意:这只是@RaymondNijland 答案的一个小扩展)如果您使用的是 MySQL 版本 >= 5.7 并且想知道 `root` 访问是否受密码保护,那么您可以使用:`mysql -Nse " select count(*) from mysql.user where user = 'root' and authentication_string is null"` (2认同)