How to change forgotten/lost Mysql root user password?

 

Question: How to change forgotten/lost Mysql root user password?

Answer:

Below instructions apply to both Windows and Linux servers:

1)          1)  Windows : Open my.ini file located in Mysql installation folder at C:\Program Files\MySQL\MySQL Server 5.1
           At end of page make the following entry:
                skip_grant_tables=1

          Linux: Open my.cnf at location /etc/mysql or /etc/ , add line
                skip_grant_tables=1


2)   Restart Mysql service.

3)   Now connect to Mysql command line using

            Mysql –u root –p

It will prompt for password. Press enter only (as blank password is set by following above steps )

4)   Execute following command to reset the password

            mysql> UPDATE mysql.user SET Password=PASSWORD('newpwd')

            WHERE User='root';

            mysql> FLUSH PRIVILEGES;

5)   Remove skip_grant_table= 1   from my.ini or my.cnf , save and exit.

      6)   Restart Mysql service.





Add Feedback