How-to : Reset a MySQL server unknown root password



This is a quick guide to reset an “unknown” MySQl  root password.

I once need to do that, and after i tried 2 or 3 different ways, i found that one to be the best in my case.




1 stop current mysql server instance

/etc/init.mysqld stop

2 restart one in safe_mode

/usr/bin/mysqld_safe --skip-grant-tables &

3 enter localhost mysql shell

mysql -h localhost

4 get the job done

mysql> USE mysql
mysql> UPDATE user
-> SET password=password('<enter_your_password_here>')
-> WHERE user='root' AND host='localhost';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> quit

You’re done…

Tagged on: , , , ,

2 thoughts on “How-to : Reset a MySQL server unknown root password

    1. pier

      Hi Gopu,

      No there is no need to flush privileges using this technique. Starting the instance in ‘safe’ mode with the


      parameter allow one to directly edit the privileges table.

Leave a Reply to Gopu Cancel reply

Your email address will not be published. Required fields are marked *

This site supports SyntaxHighlighter via WP SyntaxHighlighter. It can highlight your code.
How to highlight your code: Paste your code in the comment form, select it and then click the language link button below. This will wrap your code in a <pre> tag and format it when submitted.