关于登录MySQL时的报错
报文
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) |
解决
- 排除是否是未开启MySQL服务的原因
- 进my.cnf配置文件添加skip-grant-tables
[root@erha ~]# cat /etc/my.cnf |
我的my.cnf文件不在etc下的my.cnf中,里面包含的了一个路径,其实就在这个路径下(/etc/my.cnf.d)
[root@erha ~]# ls /etc/my.cnf.d/ |
里面有三个配置文件,进入mysql-server.cnf文件中
[root@erha ~]# cat /etc/my.cnf.d/mysql-server.cnf |
在[mysqld]下添加”skip-grant-tables”,保存后退出。
更改root账户的密码
- 无密码登录MySQL
[root@erha my.cnf.d]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 8.0.26 Source distribution
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.- 修改密码
update mysql.user set authentication_string='abcdefg' where user='root';
Query OK, 1 row affected (0.01 sec)- 刷新权限
flush privileges;
Query OK, 0 rows affected (0.01 sec)4. **退出**
exit
Bye重启mysql
[root@erha my.cnf.d]# systemctl restart mysqld |
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 erha's blog!