MySQL问题:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

问题描述:

Server version: 8.0.21-0ubuntu0.20.04.4 (Ubuntu)

root@tencent:~# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

解决方案:

1、跳过权限登录MySQL

root@tencent:~# sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf

末尾添加:skip-grant-tables
root@tencent:~# systemctl restart mysql.service
2、通过命令mysql无密码登录

3、修改密码为空

mysql> use mysql; 

mysql> update user set authentication_string='' where user='root';
Query OK, 2 rows affected (0.00 sec)
Rows matched: 2 Changed: 2 Warnings: 0

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

4、恢复步骤1修改,然后重启MySQL服务

5、修改root密码

mysql> use mysql;

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Admin@9000';
Query OK, 0 rows affected (0.00 sec)

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

mysql> exit

 

posted @ 2020-09-25 12:56  xzming8  阅读(213)  评论(0)    收藏  举报