Linux下MySQL8的密码忘记之后重置密码

1、首先关闭Mysql服务

复制代码
#service mysqld stop

关闭之后可以查看一下mysql服务状态:可以看到下面还有mysql服务的操作日志

2、找到my.cnf文件

添加skip-grant-tables设置免密登录

复制代码
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/8.0/en/server-configuration-defaults.html

[mysqld]
skip-grant-tables
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove the leading "# " to disable binary logging
# Binary logging captures changes between backups and is enabled by
# default. It's default setting is log_bin=binlog
# disable_log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
#
# Remove leading # to revert to previous value for default_authentication_plugin,
# this will increase compatibility with older clients. For background, see:
# https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_default_authentication_plugin
# default-authentication-plugin=mysql_native_password

datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
bind-address=0.0.0.0

保存编辑内容

3、重启Mysql服务

复制代码
#service mysqld start

4、将旧的密码置空

复制代码
mysql -u root -p    //提示输入密码时直接敲回车。

选择数据库mysql

复制代码
use mysql;

将密码置空

复制代码
update user set authentication_string = '' where user = 'root';

退出

复制代码
quit

5、关闭mysql服务,删掉步骤2的语句 skip-grant-tables

6、重启mysql服务

复制代码
重启服务 service mysqld restart

7、修改密码

复制代码
进入数据库
mysql -u root -p //提示输入密码时直接敲回车,刚刚已经将密码置空了
修改密码
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '在这里输入你的密码';

mysql8之后密码强制校验复杂度,密码过于简单会报错,一般校验 大写+小写+数字+特殊字符:@、_等组合尝试

相关推荐
叫我辉哥e12 小时前
### Linux命令创意组合大赛技术文章大纲
linux·运维·服务器
EverydayJoy^v^2 小时前
RH134学习进程——九.访问网络附加存储
linux·网络·学习
zhojiew2 小时前
在Lambda函数中编写和部署MCP服务器的方法
运维·ai·aws
liulilittle2 小时前
ISIF-COP香港服务器,启用OPENPPP2 VMUX全双工
运维·服务器·网络·信息与通信·通信
韩立学长2 小时前
【开题答辩实录分享】以《在线预问诊系统设计与实现》为例进行选题答辩实录分享
vue.js·spring boot·mysql
橘子132 小时前
MySQL表的基本查询(六)
数据库·mysql
杜子不疼.2 小时前
【Linux】基础IO(四):用户缓冲区深度解析
linux·运维·服务器·开发语言
海盗12342 小时前
Linux下 vim(vi)编辑器的使用-各种模式介绍
linux·编辑器·vim
春日见2 小时前
三分钟安装window Docker,并与Ubuntu(WSL)建立连接
linux·人工智能·windows·驱动开发·机器学习·docker·容器