Linux中忘记 修改Mysql密码

 

1.记得root密码的情况下

登录MySql

mysql -uroot -p
Enter password: 【输入原来的密码】
mysql>use mysql;
mysql> update user set password=passworD("123456") where user='root';
mysql> flush privileges;
mysql> exit;

注意:

如果MySql版本5.7及以上的话修改语句为

mysql> update user set authentication_string=passworD("123456") where user='root';

2.忘记root密码的情况下

首先拿到操作系统的root权限,然后kill掉Mysql服务或者手动stop掉、例如手动

service mysql stop

然后执行

mysqld_safe --skip-grant-tables &

&,表示在后台运行,不再后台运行的话,就再打开一个终端吧。

接着登录MySQL修改密码

mysql> use mysql;
mysql> UPDATE user SET password=password("123456") WHERE user='root';
mysql> flush privileges;
mysql> exit;

 

注意:

如果MySql版本5.7及以上的话修改语句为

mysql> update user set authentication_string=passworD("123456") where user='root';

 

posted @ 2022-01-25 18:06  树下水月  阅读(74)  评论(0编辑  收藏  举报