How to connect to the MySQL database in the mode without checking the password and change the lost password to a new one?

    1 answer 1

    To change the password for the superuser root, you need to connect to the MySQL server in the absence of a password check, change the password, start the server in the normal mode, connect using the new password. To do this, you need to complete a few steps:

    1. Stop mysql
      To do this, run the command in the command line:
      net stop mysql
      After stopping the server, the console window is "in standby mode", without closing this window, open a new one;
    2. Go to the directory where MySQL was installed using the command: cd c: \ <path to the bin folder> After the current position in the console points to the bin folder. Execute the command:
      mysqld --skip-grant-tables --user=root &
      As a result of the command, the server was launched in the mode in which you can connect to it without using a password
    3. Run the mysql client:
      mysql -u root
    4. Execute sql query:
      UPDATE mysql.user SET Password=PASSWORD('newpwd') WHERE User='root';
      where newpwd is the new password
    5. Apply changes: FLUSH PRIVILEGES; Further changes are saved and the root user has a new password. To log in to MySQL in standard mode, you need to start the service command: net start mysql However, an error may occur when starting the service in this case, restart the computer and connect to MySQL with a new password.