mysql8.0.15忘记root密码_mysql8.0.15无密码登录

下面介绍的是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了

原文地址:https://www.cnblogs.com/lzijiangg/p/14245345.html