beta.blog

Debian: Reset MySQL Root Password

by on Dec.21, 2011, under Linux (Ubuntu)

If you’re unable to login with your root credentials because you forgot your password or your MySQL server has been hacked, you might want to try entering the following commands into a terminal window in order to reset your password.

1. Stop the MySQL daemon:

/etc/init.d/mysql stop

OR

service mysql stop

2. Start up the database in the background using the mysqld_safe command:

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

and hit enter twice.

3. The server has been started with the –skip-grant-tables flag, so you can login using:

mysql --user=root mysql

(Note: The mysql database will be used once you’re logged in)

4. Now it’s time to set a new password (replace NEW-PASSWORD-HERE with your password):

update user set Password=PASSWORD('NEW-PASSWORD-HERE') WHERE User='root';

5. And flush the privileges:

flush privileges;

6. Exit the mysql client:

exit

7. Kill the mysql server:

pkill mysqld

8. And restart the mysql server:

/etc/init.d/mysql start

OR

service mysql start

Leave a Reply

*

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!