mysql root账户异常登录:ERROR 1698 (28000):

前言

阿里云服务器Ubuntu 18.04直接sudo apt install -y mysql-server之后,使用命令mysql -u root -p无法登录一直报错:ERROR 1698 (28000): Access denied for user 'root'@'localhost'。
问题原因及解决办法参考:https://www.cnblogs.com/leolztang/p/5094930.html

原因及解决方案:

1、查看一下user表,错误的起因就是在这里, root的plugin被修改成了auth_socket,用密码登陆的plugin应该是mysql_native_password。
查看表信息:

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

2、关于auth_socket,在官方有说明: https://dev.mysql.com/doc/mysql-security-excerpt/5.5/en/socket-authentication-plugin.html ,反正现在暂时不用它, 那就把这里改了。

mysql> update mysql.user set authentication_string=PASSWORD('newPwd'), plugin='mysql_native_password' where user='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

3、重启服务器

sudo service mysql restart
mysql -u root -p

然后就ok了

你可能感兴趣的:(mysql root账户异常登录:ERROR 1698 (28000):)