linux下mysql忘记密码的解决方法
有时候我们忘记了mysql的root密码,很多操作都无法实现。但是只要可以登录上服务器,都是有办法解决的。
1.停止mysql
可以使用 service mysql stop 来停止
[root@huawei_server /]# service mysql stop
Redirecting to /bin/systemctl stop mysql.service
[root@huawei_server /]#
不同的安装方式,停止方式可能不一样。其他还有很多办法,直接kill -9杀掉进程都行
2.直接免密码登录mysql,让输入密码的时候直接按回车即可
[root@huawei_server bin]# mysql -uroot -pEnter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.7.37-log Source distribution
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
3.修改密码,退出
mysql> use mysqlDatabase changedmysql> update mysql.user set authentication_string=password('root123456789') where user='root';Query OK, 1 row affected, 1 warning (0.05 sec)Rows matched: 1 Changed: 1 Warnings: 1
mysql> exitBye
4.重启mysql,即可使用新设置的密码登录
[root@huawei_server bin]# service mysql startRedirecting to /bin/systemctl start mysql.service[root@huawei_server bin]#

浙公网安备 33010602011771号