问题描述:
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