问题描述:
安装了MySQL后设置密码,然后登陆,不知道为啥就登不上,开始的那个临时密码也不行了。
[root@localhost ~]# mysql -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
解决方案:
方案的思路就是修改/etc/my.cnf使得不用密码进入MySQL,然后修改或查询user root的密码。
步骤:
1.vim /etc/my.cnf
2.在[mysqld]后添加skip-grant-tables
3.启动MySQL systemctl restart mysqld
4.登陆 直接输入mysql
5.修改密码 输入:
use mysel
update mysql.user set authentication_string='新密码' where user='root' ;
exit
6.将/etc/my.cnf添加的内容删掉
7.重启MySQL,完成。
————————————————————————————————————————
在进入MySQL后可以查看密码
select user, authentication_string from user;
————————————————————————————————————————
这是查看临时密码的方法
grep 'temporary password' /var/log/mysqld.log