一.忘记密码修改MySQL密码
1.修改 /etc/my.cnf 文件
vim /etc/my.cnf
2.在 【mysqld】 后面任意一个地方添加以下内容:
skip-grant-tables #跳过密码验证
3.重启MySQL
systemctl restart mysqld #重启mysql服务
4.进入MySQL
mysql -uroot -p # 无需密码,直接回车
5.修改密码
分行输入
use mysql;
update mysql.user set authentication_string=PASSWORD('想要设置的密码') where User='root';
flush privileges;
6.将2中添加的语句去掉
7.验证
systemctl restart mysqld # 重启
mysql -uroot -p #输入新密码
二.修改MySQL密码
alter user 'root'@'localhost' identified by '密码';
参考:
1.https://blog.csdn.net/Fang_Alin/article/details/126463406
2.https://www.jb51.net/article/102138.htm