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;
posted @   liwenchao1995  阅读(79)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
点击右上角即可分享
微信分享提示