参考链接: https://www.cnblogs.com/JadenFK3326/p/Ubuntu.html
连接到数据库时,提示如下错误:
connect to database error : Access denied for user 'root'@'localhost'
解决方法如下:
1、 用管理员密码登录 mysql -udebian-sys-maint -p
管理员密码存储位置:/etc/mysql
hbg@rohens:/etc/mysql$ sudo cat debian.cnf
[sudo] hbg 的密码:
# Automatically generated for Debian scripts. DO NOT TOUCH!
[client]
host = localhost
user = debian-sys-maint
password = 5Em08U7izRDbYa5J
socket = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host = localhost
user = debian-sys-maint
password = 5Em08U7izRDbYa5J
socket = /var/run/mysqld/mysqld.sock
2、修改密码
use mysql
update mysql.user set authentication_string=password('新密码') where user='root' and Host ='localhost';
update user set plugin="mysql_native_password";
flush privileges;
quit;
3、重启mysql
service mysql restart