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

相关推荐
SudosuBash4 小时前
[CS:APP 3e] 关于对 第 12 章 读/写者的一点思考和题解 (作业 12.19,12.20,12.21)
linux·并发·操作系统(os)
哈基咪怎么可能是AI14 小时前
为什么我就想要「线性历史 + Signed Commits」GitHub 却把我当猴耍 🤬🎙️
linux·github
于眠牧北14 小时前
MySQL的锁类型,表锁,行锁,MVCC中所使用的临键锁
mysql
十日十行1 天前
Linux和window共享文件夹
linux
木心月转码ing2 天前
WSL+Cpp开发环境配置
linux
Turnip12022 天前
深度解析:为什么简单的数据库"写操作"会在 MySQL 中卡住?
后端·mysql
蝎子莱莱爱打怪3 天前
Centos7中一键安装K8s集群以及Rancher安装记录
运维·后端·kubernetes
崔小汤呀3 天前
最全的docker安装笔记,包含CentOS和Ubuntu
linux·后端
何中应3 天前
vi编辑器使用
linux·后端·操作系统
何中应3 天前
Linux进程无法被kill
linux·后端·操作系统