post separator

Recover Lost MySQL root Password


ERROR 1045: Access denied for user: ‘root@localhost’ (Using password: YES)

It’s is not surprising recovering lost password in open source product is relatively easy, after all they are open. Linux is very stable and secure, so stable that once your installation complete and has been configured and secured, you can just ignore its existence, it will work just fine. This, expose most administrator to one major problem, lost passwords. Today, for some reason, I logged in to one of our client email server we setup two years back. Uptime 147 days, last login december last year. Luckily I still remember the OS password. Tried to login to mysql, failed. Tried again with all possible passwords, still no luck. Tried, history | grep mysql, yay!, there is mysql -u -p in history, try that and still failed. Being the only person that have root access to the server, Nobody else will know the password and it is not in use anyway, I decided to change it and share the steps with whoever need it.

So how to recover your root password? It’s actually not recover the password, the correct term will be recovering root privileges as what we are going to do is change the root password without having to know the original password. Follow the following steps to do so:

  1. service mysqld stop
  2. safe_mysqld ––skip-grant-tables & or mysqld_safe ––skip-grant-tables &
  3. mysql -uroot mysql
    1. Type the following command in mysql:-
    2. UPDATE user SET password=PASSWORD(”abcd”) WHERE user=”root”;
    3. FLUSH PRIVILEGES;
    4. quit
  4. service mysqld restart

Now you can gain your root privileges by using the new password you just set. Collect enough mana and summon the following command:

mysql -uroot -pabcd

If you cannot gain access, then your mana if not enough. Try again, or just set ––skip-grant-tables to completely ignore the security option, which of course is not safe and not recommended.

And a little tip for you: lost root password for linux OS, google for ‘linux single’.

RSS feed | Trackback URI

Comments »

No comments yet.

Name (required)
E-mail (required - never shown publicly)
URI
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> in your comment.
Close
E-mail It