Local Mysql database password reset

The first step: Turn off mysql database

Use administrator mode to open a command window breaks.
Here Insert Picture Description
Into the bin mysql installation directory under the directory, and then enter the closed net stop mysql mysql database
Here Insert Picture Description

Step Two: Start to skip the certification authority database

Enter mysqld --skip-grant-tables to skip the certification authority to start the database, note that if there is no response to this command is likely to fail in the current database version, use the mysqld --console --skip-grant-tables --shared -memory can to solve the problem .
Here Insert Picture Description

Step 3: Connect database permissions

Use administrator mode to open a new command window breaks , then enter the mysql installation bin directory of the file folder, you can enter the input mysql mysql database.

Here Insert Picture Description
Then you can make use mysql database access rights.
Here Insert Picture Description

Step Four: Modify the database connection password

  • If mysqld --skip-grant-tables employed in your command of the second stage is skipped certification authority, the input update user set password = password ( "123456") where user = "root";.
  • 如果你采用的是mysqld --console --skip-grant-tables --shared-memory命令,则输入alter user ‘root’@‘localhost’ identified by ‘123456’; 。注意在这里使用这个命令时报错ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement。
    Here Insert Picture Description
    需要刷新权限表,输入命令flush privileges;。注意:以上命令不要丢掉结尾分号。
    Here Insert Picture Description
    在输入上述的alter user ‘root’@‘localhost’ identified by ‘123456’; 命令即可。
    Here Insert Picture Description

注意:123456为新密码,可根据自己要求自行修改,root为用户名,我修改的为本地数据库密码。

到这里mysql本地数据库密码就修改成功了。

第五步:退出数据库并使用新密码登录数据库

输入quit即可退出数据库
Here Insert Picture Description
修改 root 密码后,需要执行下面的语句和新修改的密码。不然开启 mysql 时会出错。

可以在打开一个新的cmd窗口,进入MySQL的安装目录下的bin目录,输入mysqladmin -u root -p shutdown,然后输入你刚修改的新密码,回车。
Here Insert Picture Description
然后在输入net start mysql重启数据库。
Here Insert Picture Description
结束!!!

Reference article:
http://zwd596257180.gitee.io/blog/2019/04/16/mysql_change_password/
https://blog.csdn.net/qq_33337277/article/details/81454700
https://www.cnblogs.com/ qianzf / p / 6995376.html

Published 45 original articles · won praise 4 · Views 1572

Guess you like

Origin blog.csdn.net/y18771025420/article/details/104174726