linux下mysql忘记密码

linux下mysql忘记密码

  1. 修改配置文件
shell 复制代码
#确认你的mysql配置文件在此目录下
sudo vim /etc/mysql/my.cnf

在里面[mysqld]行下面插入skip-grant-tables

输入:wq保存配置文件

  1. 重启mysql
shell 复制代码
service mysql restart
  1. 登录mysql
shell 复制代码
#此时登录无需输入密码,按回车即可进入mysql
mysql -uroot -p
  1. 修改密码
sql 复制代码
#选中mysql数据库
use mysql;
#更新root用户密码
update user set authentication_string=PASSWORD("这里输入你要改的密码") where User='root'; 
#设置密码插件
update user set plugin="mysql_native_password";
#刷新权限
flush privileges;
#退出mysql
quit;
  1. 还原配置文件
shell 复制代码
#确认你的mysql配置文件在此目录下
sudo vim /etc/mysql/my.cnf

把里面[mysqld]行下面插入skip-grant-tables删除掉

输入:wq保存配置文件

  1. 重启mysql
shell 复制代码
service mysql restart
  1. 登录mysql即可
shell 复制代码
#输入新密码即可登录
mysql -uroot -p

我不小心把登录密码插件设置错了,可以在配置文件[mysqld]下插入default_authentication_plugin=mysql_native_password

用于修改mysql的登录校验项

相关推荐
坐怀不乱杯魂14 小时前
Linux - 缓存利用率
linux·c++·缓存
qinyia14 小时前
WisdomSSH解决硬盘直通给飞牛系统时控制器无法绑定的问题
java·linux·服务器
昵称什么的不存在14 小时前
linux安装WPS和typora等deb包,以及typora的linux版本激活
linux·运维·wps
qq192572302714 小时前
mysql高级查询
数据库·mysql
_w_z_j_14 小时前
Linux----Socket实现UDP简单服务器与客户端程序
linux·运维·服务器
默|笙14 小时前
【Linux】进程控制(4)自主shell命令行解释器
linux·运维·chrome
草莓熊Lotso14 小时前
从冯诺依曼到操作系统:打通 Linux 底层核心逻辑
linux·服务器·c++·人工智能·后端·系统架构·系统安全
石像鬼₧魂石14 小时前
ettercap 命令执行输出的详细解读
linux·学习
HABuo14 小时前
【Linux进程(二)】操作系统&Linux的进程状态深入剖析
linux·运维·服务器·c语言·c++·ubuntu·centos