mysql 5.7 Access denied for user 'root'@'localhost' solution

sudo vim /etc/mysql/debian.cnf

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



mysql -u debian-sys-maint -p
password:Ya6xoKPmeCs2xOJY

mysql> update mysql.user set authentication_string=password('root') where user='root' and Host = 'localhost';

mysql> flush privileges;
mysql> quit;
原文地址:https://www.cnblogs.com/fofawubian/p/8204849.html