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

相关推荐
小吴伴学者16 小时前
Linux RX报文处理全流程解析
linux
未若君雅裁16 小时前
MySQL慢SQL排查实战-从定位到EXPLAIN优化闭环
sql·mysql
小侯不躺平.16 小时前
C++ Boost库【2】 --stringalgo字符串算法
linux·c++·算法
jingleli2116 小时前
ssh配置内置sftp并使用密钥对登录
运维·ssh
书语时16 小时前
单体 MySQL 支撑业务的上限一般从哪里先触顶?如何论证瓶颈在 DB?
数据库·mysql
盘古信息IMS16 小时前
盘古信息 MES:赋能电子制造精益生产,实现排程、物料、质量一体化精准管控
大数据·运维·制造
夏乌_Wx16 小时前
计算机网络实践项目 | 云相册(文件互传与管理系统)
linux·计算机网络
用户8055336980316 小时前
嵌入式Linux驱动开发——设备树语法与编译工具——读懂这张"藏宝图"
linux·嵌入式
2501_9127840816 小时前
技术深度解析:Taocarts 跨境独立站系统 —— 反向海淘全链路架构设计与自动化实现
运维·自动化·独立站·taocarts