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的登录校验项

相关推荐
Doctor_Strange_DML3 分钟前
图像编辑模型服务部署过程记录
linux·缓存·docker·ai
Decay__2 小时前
PostgreSQL 运维自动化平台 —— 部署编排、监控、巡检、告警、工单闭环一体化
运维·数据库·sql·mysql·架构
0+1113 小时前
MySQL --基本查询
数据库·mysql
inferno4 小时前
十九、性能优化
数据库·sql·mysql
笔记本note5 小时前
Linux 文件系统与设备文件
linux·服务器·文件系统
无足鸟ICT5 小时前
【RHCA+】_proc_pid_cmdline
linux·运维·服务器
学以智用6 小时前
CentOS Linux 文件操作详解
linux
饿了吃洗衣凝珠7 小时前
shell循环
linux·运维·服务器
代码不停8 小时前
Linux基础知识
java·linux·数据库
东风微鸣8 小时前
Linux台式机也能指纹识别登录验证啦
linux·指纹