Penguin
Note: You are viewing an old revision of this page. View the current version.

Resetting a forgotten MySQL root password

Instructions according to MySQL Documentation

"Disable" the current passwords

If you are the SuperUser or the user mysqld runs as, take it down by sending it a kill(1) (don't use -9!!). Its PID is stored in a .pid normally found in the MySQL database directory
  1. kill `cat /mysql-data-directory/hostname.pid`

Now restart mysqld with the --skip-grant-tables option and set a new password. There are two alternatives:

Using mysqladmin

That's as simple as

mysqladmin -u root password 'mynewpassword' mysqladmin -h hostname flush-privileges

Using the mysql client

Connect to the mysqld server with
mysql -u root mysql
Issue the following commands in the mysql client
mysql> UPDATE user SET Password=PASSWORD('mynewpassword') WHERE User='root'; mysql> FLUSH PRIVILEGES;

Done.

You should now be able to connect using the new password. You can now stop mysqld and restart it normally.