64怎样重置mysql(root)密码?

  Mysql中可以使用root用户创建新用户或者修改用户的密码,但是如果当忘记root密码时,那么该怎样重置呢?这种主要分为三种不同类型的重置

  • Resetting the Root Password: Windows Systems
  • Resetting the Root Password: Unix and Unix-Like Systems
  • Resetting the Root Password: Generic Instructions

     第一种和第二种分别是针对window操作系统和unix操作系统,第三种主要是针对linux操作系统,这里就主要介绍第三种

Resetting the Root Password: Generic Instructions

  • Stop the MySQL server if necessary, then restart it with the --skip-grant-tables option. 
  • Connect to the MySQL server using the mysql client; no password is necessary because the server was started with --skip-grant-tables:   
  • In the mysql client, tell the server to reload the grant tables so that account-management statements work:
 mysql> FLUSH PRIVILEGES;

  Then change the 'root'@'localhost' account password. Replace the password with the password that you want to use. To change the password for a r  oot account with a different host name part, modify the instructions to use that host name.

 mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';

You should now be able to connect to the MySQL server as root using the new password. Stop the server and restart it normally (without the --skip-grant-tables option and without enabling the skip_networking system variable).

这里说说补充一下flush privileges

flush privileges

  重新加载mysql 的授权表, If the --skip-grant-tables option was specified at server startup to disable the MySQL privilege system, FLUSH PRIVILEGES provides a way to enable the privilege system at runtime

  FLUSH PRIVILEGES resets failed-login tracking (or enables it if the server was started with --skip-grant-tables) and unlocks any temporarily locked accounts

  

posted on 2023-01-02 14:39  太白金星有点烦  阅读(36)  评论(0)    收藏  举报

导航