(二)mysql忘记root密码

MySQL重置root密码
本文介绍如何在不同版本的MySQL中重置root用户的密码,包括5.7.6之前的版本和5.7.6及之后的版本。通过临时禁用权限表来允许root用户无需密码登录,然后更新root用户的密码并刷新权限。

(1)mysql 5.7.6以前版本

  • 修改配置文件vim /etc/my.cnf
[mysqld]
skip-grant-tables
  • 重启mysql
systemctl restart mysqld
  • 修改密码和刷新授权表
mysql>update mysql.user set password=password("redhat") where user="root" and host="localhost";
mysql>flush privileges;
  • 再次修改配置文件
#skip-grant-tables
  • 重启mysql
systemctl restart mysqld 

(2)mysql 5.7.6以后的版本

  • 修改配置文件vim /etc/my.cnf
[mysqld]
skip-grant-tables
  • 重启mysql
systemctl restart mysqld 
  • 修改密码和刷新授权表
mysql> select user,host,authentication_string from mysql.user;
mysql> update mysql.user set authentication_string=password('redhat') where user="root" and host="localhost";
mysql> flush privileges;
  • 再次修改配置文件vim /etc/my.cnf
#skip-grant-tables
  • 重启mysql
systemctl restart mysqld 

转载于:https://www.cnblogs.com/lovelinux199075/p/8878131.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值