Thursday, October 22, 2015

Resetting a forgotten MySQL root password

Resetting a forgotten MySQL root password


Problem


 You forgot you root MySQL password :)

Solution 


First, we need stop MySQL daemon:

$ sudo /etc/init.d/mysql stop

Also, we can use service command:

$ sudo service mysql stop



Next we need start MySQL in safe-mode:

$ sudo /usr/bin/mysqld_safe --skip-grant-tables

Connecting to the MySQL:

$ mysql --user=root mysql

If asked for password after this command don't enter anything, press Enter.

Now we update password in MySQL:

> UPDATE user SET Password=PASSWORD('YOUR_NEW_PASSWORD') WHERE Host='localhost' AND User='root';

Preparing to exit:

> commit;
> flush privileges;

And going out:

> exit;

Now you just need to start MySQL daemon and can use new root's password.

Enjoy!

No comments:

Post a Comment