MySQL5.7 forgets the root password and resets the password

You can try to mysqldboot in safe mode.

Note, however, mysqldthat booting in safe mode using is a bit more complicated. Here is a basic step:

  1. Find my.cnfthe file : my.cnfis the MySQL configuration file, usually located in /etc/my.cnf, /etc/mysql/my.cnfor ~/.my.cnf.

  2. Edit my.cnfthe file : [mysqld]Add the following line below the section of the file:

    skip-grant-tables
    

    This will allow MySQL to skip the privilege table the next time it starts, allowing you to log in directly.

  3. Restart the MySQL service :

    sudo systemctl stop mysqld
    sudo systemctl start mysqld
    
  4. Connect to MySQL and reset the password :

    mysql -u root
    USE mysql;
    UPDATE user SET authentication_string=PASSWORD("newpassword") WHERE User='root';
    FLUSH PRIVILEGES;
    EXIT;
    

    Replace "newpassword"with your desired new password.

  5. To restore the original my.cnfsettings : edit my.cnfthe file, remove skip-grant-tablesthe line, and restart the MySQL service again.

Remember, before editing any configuration files, it's a good idea to make a backup in case something goes wrong. .

Guess you like

Origin blog.csdn.net/u011197085/article/details/131566043