Posted by: nowiremember | April 8, 2008

Reset your root MySQL password

With the multiplication of passwords, it becomes easy to forget crummy and useless passwords like the root password of a MySQL installation (you did set a root passsword, did you ?). Here is an easy procedure in case you forget:

Stop the running MySQL server. You need to be root on your system, then:
.
# /etc/init.d/mysql stop
.
Now, we need to make a text file called an init file. The contents of this file will be executed in a moment when we restart the MySQL server in a special way. So, create a new text file in your home folder and place this in the file:

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpassword');

Obviously, substitute in your desired password (leaving the quotes intact). Save the file as passwordinit.

Now, we need to start the MySQL server with this init file. Still as root on the system, run:

# mysqld_safe --init-file=~/passwordinit &

As soon as you press Enter, the password has been changed. Now I recommend restarting the MySQL server in the normal way, as follows:

# /etc/init.d/mysql restart

And that’s it. Be more careful next time.

Originally published on FOSSwire

Leave a response

You must be logged in to post a comment.

Categories