Get back Deleted root@localhost account in MySQL

Today i was working with mysql and i added mysql users in user table , while deleting i deleted the root user….!!!

ooops this is now the problem that how to login to mysql???

i found the solution over here..

Follow this steps to get back your deleted root user

  1. service mysqld stop
  2. su – mysql
  3. mysqld_safe --skip-grant-tables &
  4. mysql
  5. use mysql
  6. INSERT INTO user VALUES
    ('localhost','root',password('passwd'),'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0);
    INSERT INTO user VALUES
    ('127.0.0.1','root',password('passwd'),'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0);
  7. commit;
  8. FLUSH PRIVILEGES;
  9. exit
  10. killall mysqld
  11. /etc/init.d/mysql start

You can confirm that the root account has been created (or is indeed missing!) by listing entries on the user table:
use mysql;
select Host,User from user;

Try this out…!!!!!!!!!!!!!!!!!!!!!!

Advertisements

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