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;

然后就可以密码登录了,

相关推荐
W.Buffer9 小时前
通用:MySQL-深入理解MySQL中的MVCC:原理、实现与实战价值
数据库·mysql
心态特好10 小时前
详解redis,MySQL,mongodb以及各自使用场景
redis·mysql·mongodb
一只小bit10 小时前
MySQL 库的操作:从创建配置到备份恢复
服务器·数据库·mysql·oracle
~光~~12 小时前
【环境配置 升级gcc】RK3588 Ubuntu20.04 gcc9升级为gcc10
ubuntu·gcc
青草地溪水旁12 小时前
linux信号(14)——SIGALRM:从“手机闹钟”看SIGALRM:进程的非阻塞定时神器
linux·信号机制
心灵宝贝13 小时前
libopenssl-1_0_0-devel-1.0.2p RPM 包安装教程(openSUSE/SLES x86_64)
linux·服务器·数据库
BullSmall14 小时前
linux zgrep命令介绍
linux·运维
程序新视界14 小时前
MySQL中,IS NULL和IS NOT NULL不会走索引?错!
数据库·mysql·dba
emma羊羊15 小时前
【文件读写】图片木马
linux·运维·服务器·网络安全·靶场
wdfk_prog15 小时前
闹钟定时器(Alarm Timer)初始化:构建可挂起的定时器基础框架
java·linux·数据库