Mysql:ERROR 1698 (28000): Access denied for user 'root'@'localhost'

ubuntu安装mysql5.7后, 通过sudo mysql_secure_installation设置了密码,但是root用户还是无法本地登录

解决方法:

1.查看默认用户名密码。

sudo cat /etc/mysql/debian.cnf 
# Automatically generated for Debian scripts. DO NOT TOUCH!
[client]
host     = localhost
user     = debian-sys-maint
password = vzK0rYfaAoejisVa
socket   = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host     = localhost
user     = debian-sys-maint
password = vzK0rYfaAoejisVa
socket   = /var/run/mysqld/mysqld.sock

2.使用默认用户名密码登录

mysql -udebian-sys-maint -p

3.登录成功后设置root密码

UPDATE mysql.user SET authentication_string=PASSWORD('root'), PLUGIN='mysql_native_password' WHERE USER='root';

接下来退出重启mysql即可正常登录

来源url
栏目