mysql 重置root密码
mysql 重置root密码
Mysql 8 版本
1.1 修改配置文件
//我这里是mysql 8.0.27版本
vim /etc/my.cnf
//添加跳过权限列表
skip-grant-tables
//重启mysql
systemctl restart mysqld
2.1 修改密码
//重启后可以不用密码直接登陆mysql
mysql //直接回车。因为配置文件跳过了权限列表
//把root的密码清空
update mysql.user set authentication_string = '' where user = 'root';
//然后exit退出,删除掉刚才/etc/my.cnf里新加的 skip-grant-tables
//再重启mysql
systemctl restart mysqld
//再次mysql进入
mysql //直接回车,因为把密码重置为空了
//修改root的密码为 Lwc263@yuan
alter user 'root'@'localhost' identified by 'Lwc263@yuan';
//刷新权限
flush privileges;
3.1 退出测试
//测试可以登陆mysql
mysql -uroot -pLwc263@yuan
Mysql 5.7重置密码
update mysql.user set authentication_string=password('YuaNian@2999!') where user='root' and Host = 'localhost';
grant all privileges on *.* to root@'%' identified by "YuaNian@2999!";
flush privileges;
本文来自博客园,作者:liwenchao1995,转载请注明原文链接:https://www.cnblogs.com/liwenchao1995/p/16473635.html

浙公网安备 33010602011771号