FAQ: Change forgotten or lost MySQL root password

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!!!

 
 
» You might also be interested in the following articles:
Quick copy/paste MySQL Replication Manual
Why use SUDO instead of SU?
Encryption files with GPG without user intervention (batch)
FAQ: How to install and configure MySQL cluster?
Sun acquires MySQL AB



» Want to stay up to date? Subscribe to our E-MAIL or RSS feed!

9 Responses to “FAQ: Change forgotten or lost MySQL root password”


  1. 1 Centrelink

    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

  2. 2 Pages

    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.,

  3. 3 ?????

    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!

  4. 4 shitty search engine

    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.

  5. 5 Glow Bracelets

    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.

  6. 6 Gaming

    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.,

  7. 7 Maplestory

    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.,

  1. 1 fluffigt.com » Blog Archive » FAQ: How to install and configure MySQL cluster?
  2. 2 fluffigt.com » Blog Archive » Quick copy/paste MySQL Replication Manual

Leave a Reply




Friendly Sites:Who is behind Linux Screw?
GeekyBits³ | Bash Cures Cancer | OMG! Ubuntu!
My SysAd Blog | Web Upd8
ZEPY | Linux config Wiki | Planet Sysadmin
a non-geek's linux notes | Linux Today
TuxArena: The arena of Tux | LinuxAlt.Com
My name is Artem N. (artiomix AT gmail DOT com) and I'm Linux/Unix, Cisco systems engineer. The main idea of Linux Screw is to share relevant knowledge, skills and observations over The Web. Here you can find a lot of information related to different Linux distributions, FreeBSD, IOS as well as a other Open Source around staff. Read more ››