Reset Forgotten MySQL Root Password

Reset MySQL Root Password in Linux:

You can reset forgotten MySQL database server password with following five easy steps in ubuntu.

Step 1: Stop the MySQL server process.

/etc/init.d/mysql stop

Step 2: Start the MySQL (mysqld) server/daemon process with the –skip-grant-tables option so that it will not prompt for password.

mysqld_safe –skip-grant-tables

Step 3: Connect to mysql server as the root user.

mysql -u root

Step 4: Setup new mysql root account password i.e. reset mysql password.

mysql> use mysql;
mysql> update user set password=PASSWORD(“NEW-ROOT-PASSWORD”) where User=’root’;
mysql> flush privileges;
mysql> quit

Step 5: Exit and restart the MySQL server.

/etc/init.d/mysql restart

Reset MySQL Root Password in Windows:

If you are using a new version of MySQL Server, such as 5.0, the methods here might not work for you, or slightly different actions may need to be applied.

Step 1. Stop your MySQL server completely. This can be done by accessing the Services window inside Windows XP and Windows Server 2003, where you can stop the MySQL service.

Step 2. Open your MS-DOS command prompt using “cmd” inside the Run window. Inside it navigate to your MySQL bin folder, such as C:MySQLbin using the cd command.

Step 3. Execute the following command in the command prompt.

mysqld.exe -u root –skip-grant-tables

Step 4. Leave the current MS-DOS command prompt as it is, and open a new MS-DOS command prompt window.

Step 5. Navigate to your MySQL bin folder, such as C:MySQLbin using the cd command.

Step 6. Enter “mysql” and press enter.

Step 7. You should now have the MySQL command prompt working. Type “use mysql;” so that we switch to the “mysql” database.

use mysql;

Step 8. Execute the following command to update the password:

UPDATE user SET Password = PASSWORD(‘NEW_PASSWORD’) WHERE User = ‘root’;

However, you can now run any SQL command that you wish.

After you are finished close the first command prompt and type “exit;” in the second command prompt windows to disconnect successfully. You can now start the MySQL service.

Please note that the 8 step process above can differ depending on the MySQL version you are using, how you configured your server, etc. However, many times you can still easily work around a problem that you experience in any of the steps

Permanent link to this article: https://blog.openshell.in/2011/01/reset-forgotten-mysql-root-password/

Leave a Reply

Your email address will not be published.