Reset MySQL root Password

If you have set a root password for MySQL previously, but have forgotten what it was, you can reset the password without much hassle.

Reset root password on Windows

  1. Logon to your system as an Administrator
  2. Stop the MySQL service
  3. Create a text file with the following SQL command.
    UPDATE mysql.user SET Password=PASSWORD('NEW_PASSWORD') WHERE User='root';
    
    FLUSH PRIVILEGES;
    
  4. Save the file as mysql-reset.txt under C:\
  5. Open a Windows Command Prompt
  6. Start the MySQL server with the –init-file option
    C:\mysql\bin\mysqld-nt --init-file=C:\mysql-reset.txt
    

    If you have installed MySQL to a location other than c:\mysql, modify the path to mysqld-nt command accordingly

  7. Delete the file created in step 3
  8. Stop the MySQL server from the Command Prompt and restart the MySQL service

You should now be able to connect to the MySQL server using your new password as root.

Reset root password on Unix / Linux

  1. Logon to the system as root or as the user that the MySQL daemon runs as
  2. Stop the MySQL daemon process
  3. Create a text file with the following SQL command.
    UPDATE mysql.user SET Password=PASSWORD('NEW_PASSWORD') WHERE User='root';
    
    FLUSH PRIVILEGES;
    
  4. Save the file as mysql-reset.txt under your home directory
  5. Start MySQL daemon with the –init-file option
    # mysqld_safe --init-file=~/mysql-reset.txt &
    
  6. Delete the file created in step 3
  7. Kill the MySQL daemon and restart the MySQL daemon

You should now be able to connect to the MySQL server using your new password as root.

ibrahim = { interested_in(unix, linux, android, open_source, reverse_engineering); coding(c, shell, perl, php, python, java, javascript, nodejs, angular, react); plays_on(xbox, ps4); linux_desktop_user(true); }