How to reset mysql root password?

4m0ni4c picture 4m0ni4c · Nov 23, 2010 · Viewed 13.2k times · Source

I have a little problem with my phpmyadmin, in fact I accidentally delete multiple user accounts. Since it is impossible to connect without the error:

# 1045 - Access denied for user 'root' @ 'localhost' (using password: NO)

I have search a little on the net before, and even the technic:

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

does not work, or I didn't understood how it worked.

I'm on FreeBSD 8.1, my version of PhpMyadmin is 2.11.

Thank you in advance for your answers.

Answer

Alexey picture Alexey · Jun 19, 2011

I summarised my solution here: http://snippets.dzone.com/posts/show/13267

sudo stop mysql
sudo mysqld --skip-grant-tables --skip-networking

mysql
mysql> update mysql.user set password = password('your_new_password') where user = 'root';
mysql> flush privileges;
mysql> exit;
sudo mysqladmin shutdown
sudo start mysql