Reset MySQL Root Password

29 Oct in mysql

First of all you will need to ensure that your database is stopped:

/etc/init.d/mysql stop

Now you should start up the databa using the mysqld_safe command:

  1. /usr/bin/mysqld_safe --skip-grant-tables &
  2. [1] 6702
  3. Starting mysqld daemon with databases from /var/lib/mysql
  4. mysqld_safe[6763]: started

Now that the server is running with the --skip-grant-tables flag you can connect to it without a password and complete the job:

  1. mysql --user=root mysql
  2. Enter password:

  1. mysql> update user set Password=PASSWORD('newPasswordHere') WHERE User='root';
  2. Query OK, 2 rows affected (0.04 sec)
  3. Rows matched: 2  Changed: 2  Warnings: 0
  4.  
  5. mysql> flush privileges;
  6. Query OK, 0 rows affected (0.02 sec)
  7.  
  8. mysql> exit
  9. Bye

Now that you've done that you just need to stop the server, so that you can go back to running a secure MySQL server with password restrictions in place.

This will now allow you to start the server:

  1. /etc/init.d/mysql start
  2. Starting MySQL database server: mysqld.
  3. Checking for corrupt, not cleanly closed and upgrade needing tables..

Thats it! Now you should verify this by connecting with your new password.

Comments

Post new comment

By submitting this form, you accept the Mollom privacy policy.

Pacific Simplicity 2010 All rights reserved. Contact