MySQL8 重置密码

MySQL8 重置密码

MySQL8 忘记密码怎么办?


sudo vi /etc/mysql/my.cnf
# 添加以下内容
[mysqld]
skip-grant-tables

# 保存后重启MySQL
sudo service mysqld restart

# 无密码进入MySQL
mysql -uroot -p
mysql> alter user 'root'@'%' identified by '';
mysql> flush privileges;
mysql> exit

# 将配置文件复原
sudo vi /etc/mysql/my.cnf

# 注释掉之前添加的内容, 修改为以下内容
[mysqld]
# skip-grant-tables

# 重启MySQL
sudo service mysqld restart

# 空密码进入MySQL
mysql -uroot -p
mysql> alter user 'root'@'%' identified by '123456'
mysql> flush privileges;

参考:

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×