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;

相关推荐
阿里云大数据AI技术16 小时前
阿里云 EMR AI 助手正式发布:从问答工具到全栈智能运维助手
运维·人工智能
orion571 天前
Missing Semester Class1:course overview and introduction of shell
linux
SkyWalking中文站2 天前
认识 Horizon UI · 6/17:Trace 探索器
运维·监控·自动化运维
用户120487221612 天前
Linux驱动编译与加载
linux·嵌入式
火车叼位2 天前
写给初级开发者:SSL、SSH、HTTPS 与证书体系全解析
运维
用户805533698032 天前
Input 子系统架构:Core、Handler、Driver 三层是怎么协作的
linux·嵌入式
用户805533698032 天前
RK-Forge外设系列开篇 - 把板子从「能启动」变成「能用」:Ethernet/SPI/MMC 三个纯接线外设
linux·github·嵌入式
小猿姐2 天前
唯品会大规模数据库云原生实践:基于 KubeBlocks 管理数千实例的统一运维之路
运维·elasticsearch·云原生
七歌杜金房2 天前
我终于又有了自己的 Linux 电脑
linux·debian·mac
SkyWalking中文站3 天前
认识 Horizon UI · 5/17:3D 基础设施地图
运维·监控·自动化运维