Reset a forgotten root password for your mysql database

Did you forget the root password for your mysql database?  Don’t fret.  Follow these simple steps to reset it.  You will need to have root access to your server to do this.

(I’m performing this on a debian/ubuntu server.  The redhat/fedora command for stopping/starting the mysql service will be very similar)

(1) Stop your database

$ sudo service mysql stop

(2) Start the database in a full access and full privilege mode

$ sudo mysqld_safe –skip-grant-tables –skip-networking &

(3) Logon without a password

$ mysql -u root mysql

(4) Reset the password

mysql>  update user set Password=PASSWORD(‘my_new_password”) where user=’root’;
mysql>  flush privileges;
mysql>  exit;

(5) Kill the running database and restart it as normal.

$ sudo pkill mysqld
$ sudo service mysql start

You should be able to logon now with  your new password.

Advertisements

2 thoughts on “Reset a forgotten root password for your mysql database

  1. It’s a pity you don’t have a donate button!
    I’d certainly donate to this superb blog! I guess for now i’ll settle for book-marking and adding your RSS feed to my Google
    account. I look forward to brand new updates and will share this website
    with my Facebook group. Chat soon!

  2. You are so interesting! I don’t think I’ve truly read anything like this before.
    So wonderful to find someone with a few original thoughts on this subject
    matter. Really.. thanks for starting this up.
    This site is something that is required on the web, someone with a little originality!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s