Resetting MySQL Passwords

I downloaded a Ubuntu 8.10 image with MySQL server, but the root password was set to something other than the standard password. Logging in without a password or username didn’t give me enough permissions to set my own users and change passwords. Here is the solution for this problem (thanks Keystone IT Tech!).

Basically, it comes down to killing mysql server, re-running it without the grant tables, setting the password and then restarting it in normal mode. To quote the linked website (Keystone IT Tech):

sudo su
kill `cat /var/run/mysqld/`
mysqld --skip-grant-tables &
mysql -u root
UPDATE mysql.user SET Password=PASSWORD ('newpassword') WHERE User = 'root';
kill `cat /var/run/mysqld/`
mysqld &
mysql -u root -p

Very cool.

Leave a Reply