The following steps describe the procedure to reset the mysql root password on Linux.

1) Stop the mysql server

/etc/init.d/mysql stop

2) Start the mysql server manually without permission tables which allows us to login as root user without password:

mysqld_safe --skip-grant-tables &

3) Login into mysql as root user without a password and switch to the "mysql" database:

mysql -u root mysql

Then execute this SQL query to set a new password for the mysql root user:

use mysql;
update user set Password=PASSWORD('mynewpassword') WHERE User='root';

(Replace "mynewpassword" with the new root password in the above command).

Then logout from the mysql prompt by typing:

exit

4) Now bring back the running mysql instance into the foreground by typing:

fg

and then press [ctrl] + c to kill the mysql process.

5) Start the mysql server again:

/etc/init.d/mysql start

How to reset the MySQL root password
Facebooktwittergoogle_plusredditlinkedinmail
Tagged on:         

7 thoughts on “How to reset the MySQL root password

  • November 5, 2009 at 7:24 pm
    Permalink

    Thanks,

    Do we need to update “/usr/local/ispconfig/server/lib/mysql_clientdb.conf” too ?

    Reply
  • November 6, 2009 at 11:35 am
    Permalink

    Yes, if you use ISPConfig 3.

    Reply
  • October 14, 2013 at 8:21 pm
    Permalink

    Hello, easier is use debian sys user login located here /etc/mysql/debian.cnf

    Reply
  • February 4, 2014 at 11:36 am
    Permalink

    It did not worked for me.

    I had to use:
    mysqladmin -u root -p’oldpassword’ password ‘newpass’

    And changed the newpass in the file /usr/local/ispconfig/server/lib/mysql_clientdb.conf

    But I still am getting the same error at the monitor:
    Unable to connect to the database: Access denied for user ‘root’@’localhost’ (using password: YES)

    Reply
    • February 4, 2014 at 11:48 am
      Permalink

      It updated now, I removed the error:
      Unable to connect to the database: Access denied for user ‘root’@’localhost’ (using password: YES) from the log

      And it updated successfully!

      Reply
  • April 16, 2015 at 2:32 pm
    Permalink

    Thanks brother.
    Its good !

    Reply
  • August 31, 2015 at 12:47 am
    Permalink

    Thanks for getting me ISP config file location 😀 it helped me to locate it without tearing my hear 😀

    Reply

Leave a Reply

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