centos中mysql8忘记密码的操作步骤

1、编辑/etc/my.cnf文件,在末尾出增加 skip-grant-tables

bash 复制代码
[mysqld]
datadir=/opt/data1/mysql8/data
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysql/mysqld.log
pid-file=/run/mysqld/mysqld.pid
bind-address=0.0.0.0
skip-grant-tables

2、 重启mysql服务

systemctl restart mysqld

3、登录mysql,并重置root密码为空

bash 复制代码
mysql -uroot
use mysql;
update user set authentication_string='' where User='root';
flush privileges;
quit;

4、将 /etc/my.cnf 中 的 skip-grant-tables 去掉;

5、再次重启mysql服务

systemctl restart mysqld

6、再次登录mysql,登录密码为空,然后修改root密码

mysql -uroot

use mysql;

ALTER user 'root'@'%' IDENTIFIED WITH mysql_native_password BY '你的密码';

flush privileges;

相关推荐
乱蜂朝王10 分钟前
Ubuntu 20.04安装CUDA 11.8
linux·运维·ubuntu
梁洪飞1 小时前
clk学习
linux·arm开发·嵌入式硬件·arm
Lw老王要学习1 小时前
Windows基础篇第一章_01VMware虚拟机安装window10
运维·windows·虚拟机
~光~~2 小时前
【嵌入式linux驱动——点亮led】基于鲁班猫4 rk3588s
linux·点灯·嵌入式linux驱动
yuanmenghao2 小时前
车载Linux 系统问题定位方法论与实战系列 - 车载 Linux 平台问题定位规范
linux·运维·服务器·网络·c++
vQAvXEsg2 小时前
基于遗传算法的电动汽车有序充放电优化探索
centos
qq_589568103 小时前
centos6.8镜像源yum install不成功,无法通过镜像源下载的解决方式
linux·运维·centos
weixin_516023074 小时前
linux下fcitx5拼音的安装
linux·运维·服务器
hunter14505 小时前
Linux 进程与计划任务
linux·运维·服务器
楼田莉子5 小时前
Linux学习之磁盘与Ext系列文件
linux·运维·服务器·c语言·学习