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;

相关推荐
云边云科技4 分钟前
零售行业新店网络零接触部署场景下,如何选择SDWAN
运维·服务器·网络·人工智能·安全·边缘计算·零售
城管不管16 分钟前
Docker核心---数据卷(堵门秘籍)
运维·docker·容器
AOwhisky29 分钟前
Linux 文本处理三剑客:awk、grep、sed 完全指南
linux·运维·服务器·网络·云计算·运维开发
Gavin_9151 小时前
从零开始部署经典开源项目管理系统最新版redmine6-Linux Debian12
linux·ruby on rails·开源·debian·ruby·redmine
xuanerya1 小时前
使用 SSH 方式克隆 GitHub 仓库没有权限解决办法
运维·ssh·github
花小璇学linux1 小时前
imx6ull-驱动开发篇31——Linux异步通知
linux·驱动开发·嵌入式软件
shelutai1 小时前
ubuntu 编译ffmpeg6.1 增加drawtext,libx264,libx265等
linux·ubuntu·ffmpeg
runfarther2 小时前
搭建LLaMA-Factory环境
linux·运维·服务器·python·自然语言处理·ai编程·llama-factory
百思可瑞教育2 小时前
Spring Cloud Gateway 负载均衡全面指南
运维·负载均衡·北京百思可瑞教育·百思可瑞教育·北京百思教育
hello_ world.2 小时前
RHCA10NUMA
linux