1)停止mysql服务
[root@web ~]#service mysqld stop
2)配置文件种取消授权表
[root@web ~]# vim /etc/my.cnf
[root@web ~]# grep grant /etc/my.cnf
skip-grant-tables
3)启动mysql
[root@web ~]#service mysqld start
4)重置密码-更新字段值,注意密码字符需要使用password('')函数加密
mysql> update user set authentication_string=password('root') where user='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> exit
在已知root密码情况下,更改密码
[root@web ~]#mysqladmin -uroot -p password('magedu')
重置密码三中方法:
1)
mysql>set password for root@localhost=password('magedu');
2)
mysql>grant all privileges on *.* to root@localhost identified by 'magedu';
3)
update mysql.user set authentication_string=password('root') where user='root' and host='localhost';
忘记mysql的root密码重置的三种方法
于 2021-05-11 10:07:51 首次发布