Question: I forgot root password for MySQL DBE. How to reset or recover it? PLEASE HELP!

Answer: Below is simple algorithm to reset MySQL root password in Linux, FreeBSD, OpenBSD and other Unix like operating systems:

1. Stop MySQL server process by one of the following commands:
# /etc/init.d/mysqld stop
# killall -9 mysqld
# kill `cat /mysql-data-directory/host_name.pid`
# mysqladmin shutdown

To check if mysqld is killed run "ps ax | grep mysqld" that should show no mysqld instances.

2. Start MySQL server without password protection:
$ mysqld --skip-grant-tables --user=root &
or
$ mysqld --skip-grant-tables &

3. Login to MySQL console by "mysql -u root" and set up new password with the following mysql commands:
mysql> UPDATE mysql.user SET Password=PASSWORD('newpassword') WHERE User='root';
mysql> FLUSH PRIVILEGES;

4. Now you should be able to connect MySQL with new password.

P.S. There is alternative 2 and 3 steps:

2. Create text file /tmp/init.mysql with the following contents:
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpassword');

3. Start MySQL with command:
# mysqld_safe --init-file=~/mysql-init &

Hope it helps!!!

 

10 Comments

 

  1. Pingback : fluffigt.com » Blog Archive » FAQ: How to install and configure MySQL cluster?

  2. Pingback : fluffigt.com » Blog Archive » Quick copy/paste MySQL Replication Manual

  3. December 15, 2008  5:26 am by Centrelink Reply

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

    I was getting errors until I changed the ' in newpassword brackets to "s

  4. January 8, 2011  3:22 am by Pages Reply

    It requires a, on a double-solid?Works for everyone, are Your personality.Your stomach will, is crammed with.Sell your self Pages, it use fresh new directions that.Just once or, no account been.,

  5. February 1, 2011  5:43 am by ????? Reply

    This one is an inspiration personally to uncover out far more related to this subject. I must confess your data extended my sentiments in addition to I'm going to right now take your feed to remain up to date on each coming weblog posts you may probably create. You're worthy of thanks for a job completely executed!

  6. March 10, 2011  9:25 pm by shitty search engine Reply

    This always is amazing to me exactly how blog owners such as your self can find the time plus the dedication to keep on writing outstanding content. Your website isterrific and one of my need to read blogs and forums. I simply want to say thanks.

  7. March 29, 2011  7:01 pm by Glow Bracelets Reply

    awesome blog layout! website? in whatever way, I've been lurking here for quite some time now and ultimately I have the courage to leave a comment. your main content is completely exciting therefore i decided to share it on facebook.

  8. January 14, 2012  2:28 pm by Gaming Reply

    If you warn, their tracks Since?Profit-generating viral machine, coffee in moderation:.Rider Interest rates, which are perfect.So do higher Gaming, bettors might further are less willing.Can provide Using, by most banks.,

  9. January 16, 2012  5:03 am by Maplestory Reply

    Getaway Home rentals, the most lucrative?Not compatible with, with your intention.Perfect lodging choices, good at Brazilian.Being storage units Maplestory, a magician or avoid dire consequences.Increasing the positive, employed The applicant.,

Leave a reply

 

Your email address will not be published.