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;

相关推荐
木头左6 小时前
【Nginx】内网服务源 IP 白名单实战:动态域名解析放行网段 + 端口接管零改造
运维·nginx·白名单·反向代理
Linux-lucky6 小时前
45-Linux学习之旅之防火墙与WEB加固
linux·前端·网络·学习·ubuntu
禁默6 小时前
启元 Q1 二次开发实践:Ubuntu 部署与仿真验证,从 PrimeConsole 到 ROS 2 Humble + RViz
linux·运维·ubuntu
skywalk81637 小时前
把 去也网站 从 Ubuntu 搬到 FreeBSD:一次 Service Jail + nginx 的部署实录
linux·运维·nginx·ubuntu·freebsd
翔云1234568 小时前
RocksDB中,客户端每写入一次数据,需要访问几次磁盘
运维·数据库·mysql
爱莉希雅&&&9 小时前
GitLab 完整学习笔记
linux·运维·服务器
风笙9789 小时前
[文件系统]文件系统挂载与卸载详解
linux
GeW9 小时前
新质生产力路线图解读:数据库性能优化与Linux调优专场
linux·数据库
小杨爱科普10 小时前
制造业上自动化改造,改造部分的专利到底归谁
运维·经验分享·自动化
陈希12311 小时前
Linux 服务器性能排查手册(2026):CPU、内存、磁盘IO、网络四大瓶颈定位
linux·服务器·网络