您现在的位置是:首页 > 技术博客 > mysql8.0.15忘记root密码或者mysql8.0.15无密码登录

mysql8.0.15忘记root密码或者mysql8.0.15无密码登录

2021-06-21文远技术博客632442

下面介绍的是mysql8.0.15忘记root密码或者mysql8.0.15无密码登录

一、修改配置文件

# 修改mysql配置文件,在[mysqld]下面加上 skip-grant-tables
# 保存并退出vi
[root@VM-0-15-centos ~]# vi /etc/my.cnf

# 重启mysql服务
[root@VM-0-15-centos ~]# /etc/init.d/mysql restart

二、登录mysql

# 提示输入密码直接回车
[root@VM-0-15-centos sql_log]# mysql -uroot -p


三、修改密码

mysql> use mysql;
Database changed
# 先把密码设置成空
mysql> update mysql.user set authentication_string="" where user="root";

# 设置密码不过期
mysql> update mysql.user set password_expired = 'N' where user = 'root';

#更新
mysql> flush privileges;

把配置文件的 skip-grant-tables 删除,重启mysql服务,直接回车,再次登录

运行mysql8专有的修改密码方式

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';


重新用新密码登录mysql 就OK了

文章评论

看完文章了吗?谁便说点吧

发表 captcha
游客_1625035934 2021-06-30 14:52:14
<img src="/static/index/jquery-pinglun/images/laugh.gif" title="[哈哈]"><img src="/static/index/jquery-pinglun/images/laugh.gif" title="[哈哈]"><img src="/static/index/jquery-pinglun/images/laugh.gif" title="[哈哈]">
游客_1625036625 2021-06-30 15:03:45
<img src="/static/index/jquery-pinglun/images/cj_thumb.gif" title="[吃惊]">
游客_1625036813 2021-06-30 15:06:53
<img src="/static/index/jquery-pinglun/images/ldln_thumb.gif" title="[懒得理你]">
游客_1625036842 2021-06-30 15:07:23
<img src="/static/index/jquery-pinglun/images/t_thumb.gif" title="[吐]">