ubuntu安装mysql 8.0忘记root初始密码,如何重新修改密码

1、停止mysql服务

$ service mysql stop

2、修改my.cnf文件

修改my.cnf文件,在文件新增 skip-grant-tables,在启动mysql时不启动grant-tables,授权表

$ sudo vim /etc/mysql/my.cnf

mysqld

skip-grant-tables

3、启动mysql服务

service mysql restart

4.清空密码

use mysql;

update user set authentication_string='' where user='root';

5.注释掉skip-grant-tables后重启mysql

service mysql restart

6.设置新密码

update user set plugin='mysql_native_password' where user='root'; #更改加密方式

alter user 'root'@'localhost' IDENTIFIED BY '123456';#设置密码

FLUSH PRIVILEGES;

然后就可以密码登录了,

相关推荐
chlk12320 小时前
Linux文件权限完全图解:读懂 ls -l 和 chmod 755 背后的秘密
linux·操作系统
舒一笑20 小时前
Ubuntu系统安装CodeX出现问题
linux·后端
改一下配置文件21 小时前
Ubuntu24.04安装NVIDIA驱动完整指南(含Secure Boot解决方案)
linux
深紫色的三北六号1 天前
Linux 服务器磁盘扩容与目录迁移:rsync + bind mount 实现服务无感迁移(无需修改配置)
linux·扩容·服务迁移
SudosuBash1 天前
[CS:APP 3e] 关于对 第 12 章 读/写者的一点思考和题解 (作业 12.19,12.20,12.21)
linux·并发·操作系统(os)
哈基咪怎么可能是AI2 天前
为什么我就想要「线性历史 + Signed Commits」GitHub 却把我当猴耍 🤬🎙️
linux·github
于眠牧北2 天前
MySQL的锁类型,表锁,行锁,MVCC中所使用的临键锁
mysql
十日十行3 天前
Linux和window共享文件夹
linux
木心月转码ing3 天前
WSL+Cpp开发环境配置
linux
Turnip12024 天前
深度解析:为什么简单的数据库"写操作"会在 MySQL 中卡住?
后端·mysql