mysql出现ERROR 1698 (28000): Access denied for user 'root'@'localhost'

MySQL版本

5.7.27-0ubuntu0.18.04.1

原因

root的plugin属性错误。

$ sudo mysql -u root
mysql> select @@validate_password_policy;
ERROR 1193 (HY000): Unknown system variable 'validate_password_policy'
mysql> select user, plugin from mysql.user;
+------------------+-----------------------+
| user             | plugin                |
+------------------+-----------------------+
| root             | auth_socket           |
| mysql.session    | mysql_native_password |
| mysql.sys        | mysql_native_password |
| debian-sys-maint | mysql_native_password |
| cloudmanager     | mysql_native_password |
+------------------+-----------------------+
5 rows in set (0.01 sec)

需要将root的plugin属性修改为mysql_native_password。

解决

$ sudo mysql -u root
mysql> USE mysql;
mysql> UPDATE user SET plugin='mysql_native_password' WHERE User='root';
mysql> FLUSH PRIVILEGES;
mysql> exit;
$ service mysql restart

问题解决。

你可能感兴趣的:(MySQL)