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;

相关推荐
我科绝伦(Huanhuan Zhou)1 小时前
分享一个服务故障自愈系统
运维·人工智能·自动化
失伟2 小时前
Stratovirt安装及使用
运维·虚拟化
牛马鸡niumasi2 小时前
C/C++ 程序编译过程、静态/动态链接、静态/动态库
linux
捧月华如3 小时前
Linux 系统性能压测工具全景指南(含工程实战)
linux·运维·服务器
YMWM_3 小时前
export MPLBACKEND=Agg命令使用
linux·python
s19134838482d3 小时前
vlan实验报告
运维·服务器·网络
想唱rap3 小时前
线程的同步与互斥
linux·运维·服务器·数据库·mysql
格林威3 小时前
SSD 写入速度测试命令(Linux)(基于工业相机高速存储)
linux·运维·开发语言·人工智能·数码相机·计算机视觉·工业相机
勇闯逆流河4 小时前
【LInux】linux控制(进程替换,自主shell的实现详解)
linux·运维·服务器
IMPYLH4 小时前
Linux 的 ls 命令
linux·运维·服务器·bash