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
- Logon to your system as an Administrator
- Stop the MySQL service
- Create a text file with the following SQL command.
123UPDATE mysql.user SET Password=PASSWORD('NEW_PASSWORD') WHERE User='root';FLUSH PRIVILEGES;
- Save the file as mysql-reset.txt under C:\
- Open a Windows Command Prompt
- Start the MySQL server with the –init-file option
1C:\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 tomysqld-nt
command accordingly - Delete the file created in step 3
- 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
- Logon to the system as root or as the user that the MySQL daemon runs as
- Stop the MySQL daemon process
- Create a text file with the following SQL command.
123UPDATE mysql.user SET Password=PASSWORD('NEW_PASSWORD') WHERE User='root';FLUSH PRIVILEGES;
- Save the file as mysql-reset.txt under your home directory
- Start MySQL daemon with the –init-file option
1# mysqld_safe --init-file=~/mysql-reset.txt &
- Delete the file created in step 3
- 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.