Rescuing lost mysql root password

Run this:
mysqld_safe --skip-grant-tables --user=root &
Then:

UPDATE mysql.user SET Password=PASSWORD('newpwd') WHERE User='root';
FLUSH PRIVILEGES;

Unfortunately, the info on the mysql site seems to be a bit wrong!

Comments (3)

JohnOctober 12th, 2005 at 9:39 am

It should be here:
/usr/bin/mysqld_safe

If not, try:
locate mysqld_safe

Remember though, you’ll have to be root to use this, or use sudo /usr/bin/mysqld_safe.

michelleMay 31st, 2006 at 4:51 am

need double quotes around password and user:

UPDATE mysql.user SET Password=PASSWORD(“newpwd”) WHERE User=”root”;

as john mentioned above, you have to use sudo

andyApril 18th, 2008 at 12:13 am

Thanks John.

for newbies like me: you need to login to the mysql server before you can update the tables (#2 step). It will let you login without a password. Then restart it :)

Mine accepted single quotes v5 on debian etch. If i remember correctly i believe version 4 also accepts single quotes.

Leave a comment

Your comment