Main Content

Forgotten / lost MySQL root password

Archive - Originally posted on "The Horse's Mouth" - 2015-05-16 14:10:09 - Graham Ellis

OK - I admit it. A very silly thing to do. I had lost / forgotten my MySQL password, and needed to do some admin work.

1. Log in to server as root

2. Stop the database server
  /etc/init.d mysql.server stop

3. Start the database server without password check
  /usr/local/mysql/bin/mysqld_safe --skip-grant-tables  

4. Manually change the grant tables
  /usr/local/mysql/bin/mysql -uroot
  use mysql;
  update user set password=PASSWORD("newpasswordhere") where user="root";
  flush privileges;
  quit


5. logout (which nicely kills the backgrounded daemon)

6. Log in as root again

7. Restart the server normally
  /etc/init.d mysql.server stop

8 Logout