Activities

April 2010
M T W T F S S
« Mar   May »
 1234
567891011
12131415161718
19202122232425
2627282930  

MySQL : Forgot root password

Here is the steps to re-set the forgot password on MySQL

1.

mysqld_safe --skip-grant-tables &


This command will start the mysql service wihtout looking on the privileges assigned for DB/Users. So anyone can login to this server. But you can’t execute any command against the ‘mysql”database.

2. Log to Mysql console and use sql query for resetting password.

mysql> use mysql;
     mysql>update user set Password=PASSWORD('emtypass') where user='root';
   mysql>flush privileges;

3. Restart MySQL and login with your newpass
# Kill the mysqld_safe dameon

 root@domU-12-31-38-04-DD-B2 ec2-user]# service mysqld stop
110803 04:13:17 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
Stopping mysqld:                                           [  OK  ]
[1]+  Done                    mysqld_safe --skip-grant-tables
[root@domU-12-31-38-04-DD-B2 ec2-user]#

OR

[root@rc-090 ~]# ps -ax | grep mysqld
Warning: bad syntax, perhaps a bogus ‘-‘? See /usr/share/doc/procps-3.2.7/FAQ
2435 pts/7 S+ 0:00 /bin/sh /usr/bin/mysqld_safe –skip-grant-tables
2481 pts/7 Sl+ 0:00 /usr/libexec/mysqld –basedir=/usr –datadir=/var/lib/mysql –user=mysql –pid-file=/var/run/mysqld/mysqld.pid –skip-external-locking –socket=/var/lib/mysql/mysql.sock –skip-grant-tables
2528 pts/5 S+ 0:00 grep mysqld
[root@rc-090 ~]# kill -9 2435
[root@rc-090 ~]# service mysqld restart
Stopping MySQL: [ OK ]
Starting MySQL: [ OK ]

Test the new password is working,

[root@rc-090 ~]# mysql -uroot -p

Also there an option to change the root password

[root@rc-090 ~]# mysqladmin -u root password newrootpass -uroot -p

This may requires you to enter the older root password to make this work

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>