Skip to content

本地MySql重置密码

约 284 字小于 1 分钟

mysql数据库

2019-5-27

原理:通过跳过表授权,跳过密码直接在表里更新密码

  1. 找到my.ini一般在C:\Program Files\MySQL\MySQL Server 5.7\bin

    ...
    [mysqld]
    
    # The next three options are mutually exclusive to SERVER_PORT below.
    # skip-networking
    
    # enable-named-pipe

    找到这个片段,改为

    ...
    [mysqld]
    skip-grant-tables
    # The next three options are mutually exclusive to SERVER_PORT below.
    # skip-networking
    
    # enable-named-pipe
  2. 重启 mysql 服务

  3. 管理员打开命令行,密码不用输入直接回车

    1.mysql -u root -p
    2.update mysql.user set authentication_string=password('654321') where user = 'root';
    3.flush privileges;
    4.exit

效果:

C:\Program Files\MySQL\MySQL Server 5.7\bin>mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.20-log MySQL Community Server (GPL)

Copyright (c) 2000, 2017, 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>
mysql> update mysql.user set authentication_string=password('654321') where user = 'root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1

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

mysql> exit
Bye

完了重启数据库服务!