MySQL5.7忘记root密码

1)停止mysql服务

systemctl stop mysqld

2)跳过权限验证启动mysql

 mysqld --skip-grant-tables --user=root

3)新开一个shell客户端,直接输入mysql回车就能登陆

[root@localhost ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.25 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

4)重置mysql的密码

mysql> update user set authentication_string = password('root') where user = 'root' ;
Query OK, 2 rows affected, 1 warning (0.00 sec)
Rows matched: 2  Changed: 2  Warnings: 1

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

5)退出,重启mysql,就可以使用新密码登录

[root@localhost ~]# systemctl start mysqld
[root@localhost ~]# mysql -uroot -proot
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.25 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

你可能感兴趣的:(后端,java)