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

相关推荐
聆风吟º3 小时前
CANN开源项目深度实践:基于amct-toolkit实现自动化模型量化与精度保障策略
运维·开源·自动化·cann
Coder个人博客3 小时前
Linux6.19-ARM64 mm mmu子模块深入分析
大数据·linux·车载系统·系统架构·系统安全·鸿蒙系统
剩下了什么5 小时前
MySQL JSON_SET() 函数
数据库·mysql·json
较劲男子汉6 小时前
CANN Runtime零拷贝传输技术源码实战 彻底打通Host与Device的数据传输壁垒
运维·服务器·数据库·cann
java搬砖工-苤-初心不变6 小时前
MySQL 主从复制配置完全指南:从原理到实践
数据库·mysql
Doro再努力6 小时前
Vim 快速上手实操手册:从入门到生产环境实战
linux·编辑器·vim
wypywyp6 小时前
8. ubuntu 虚拟机 linux 服务器 TCP/IP 概念辨析
linux·服务器·ubuntu
风流倜傥唐伯虎6 小时前
Spring Boot Jar包生产级启停脚本
java·运维·spring boot
Doro再努力6 小时前
【Linux操作系统10】Makefile深度解析:从依赖推导到有效编译
android·linux·运维·服务器·编辑器·vim
senijusene7 小时前
Linux软件编程:IO编程,标准IO(1)
linux·运维·服务器