数据库学习日常案例20231205-MYSQL 8.0 重置root密码

1 首先ps -ef|grep mysqld查看对应的进程信息

ps -ef|grep mysqld

主要看对应的sokcet以及启动脚本信息,

1.vim /etc/my.cnf,添加 skip-grant-table(跳过权限验证),注意是加在mysqld模块下;

2.重启mysql服务;

systemctl stop mysqld //停止mysql服务
systemctl restart mysqld //重启mysql
systemctl status mysqld //查看mysql服务状态

3.进入mysql -uroot -p, 此时可直接无密码登录;

4.进入mysql数据库下进行旧密码置空(Mysql8.0),先将mysql.user表中的root用户旧密码置空;

// 备注:Mysql5.7+ password字段 已改成 authentication_string字段
update user set authentication_string='' where user='root'; 
 

5.设置新密码(Mysql8.0),注意先查询一下user表看下root用户此时对应的host此时是否是localhost,然后对应做修改,我的这里之前修改过远程连接权限,所以改成了%,别无脑copy,对应自己查询出来的host值进行修改;

alter user 'root'@'%' identified by 'newpassword';
6.vim /etc/my.cnf,删除mysqld中的 skip-grant-table;

7.再次重启mysql;

8.使用新密码登录 mysql;


————————————————
版权声明:本文为CSDN博主「@晴天_」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_40988139/article/details/125377084

你可能感兴趣的:(MYSQL数据字典应用管理,MYSQL基础管理,数据库,学习,mysql)