《MySQL系列-部署维护》MySQL8.0版本如何正确找回密码?

MySQL8.0找回密码

1.Windows服务器上部署有MySQL8.0服务,需要找回密码。但是按照常规的方法,在my.ini文件中添加skip-grant-tables参数,并重启MySQL并未生效

C:\Users\EDZ>mysql -uroot -p
Enter password:
ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost:3306' (10061)

2.经过资料查找,采用如下方法:

尝试过mysqld --skip-grant-tables命令,但是依旧无法免密登录

mysqld --console --skip-grant-tables --shared-memory

D:\software\MySQL\mysql-8.0.27-winx64\bin>mysqld --console --skip-grant-tables --shared-memory
2023-03-28T09:00:39.296919Z 0 [Warning] [MY-000081] [Server] option 'wait_timeout': unsigned value 31536000 adjusted to 2147483.
2023-03-28T09:00:39.297172Z 0 [System] [MY-010116] [Server] D:\software\MySQL\mysql-8.0.27-winx64\bin\mysqld.exe (mysqld 8.0.27) starting as process 15764
2023-03-28T09:00:39.313331Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-03-28T09:00:39.715547Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-03-28T09:00:40.031200Z 0 [Warning] [MY-011311] [Server] Plugin mysqlx reported: 'All I/O interfaces are disabled, X Protocol won't be accessible'
2023-03-28T09:00:40.112717Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1 is enabled for channel mysql_main
2023-03-28T09:00:40.112899Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1.1 is enabled for channel mysql_main
2023-03-28T09:00:40.115167Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2023-03-28T09:00:40.115372Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2023-03-28T09:00:40.137087Z 0 [System] [MY-010931] [Server] D:\software\MySQL\mysql-8.0.27-winx64\bin\mysqld.exe: ready for connections. Version: '8.0.27'  socket: ''  port: 0  MySQL Community Server - GPL.

3.重启开启一个DOS窗口,已经可以免密登录。登陆后即可以关闭刚刚mysqld启动的DOS窗口。然后修改密码后,重新登陆即可

C:\Users\EDZ>mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 8.0.27 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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> flush privileges;
Query OK, 0 rows affected (0.03 sec)


mysql> alter user 'root'@'localhost' identified by 'Zxy@123456';
Query OK, 0 rows affected (0.01 sec)

猜你喜欢

转载自blog.csdn.net/m0_51197424/article/details/129824504