Reset Forgotten Mysql Server root passwod for linux (CentOS/RedHat/Fedora)

You can reset MySQL Server root password with these following easy steps:

1.  Login as user root and stop MySQL daemon with following command:

[root@localhost ~]# /etc/rc.d/init.d/mysqld stop
Stopping mysqld:                                           [  OK  ]
Or
[root@localhost ~]# service mysqld stop
Stopping mysqld:                                           [  OK  ]

2. Now start up the MySQL daemon in safe mode and skip the grant tables which store the passwords.

[root@localhost ~]# /usr/bin/mysqld_safe –skip-grant-tables &
[1] 2912
[root@localhost ~]# 150403 10:03:44 mysqld_safe Logging to ‘/var/log/mysqld.log’.
150403 10:03:44 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

3. Now that the MySQL Server is running with the –skip-grant-tables flag you connect to it without a password.

[root@localhost ~]# mysql -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

mysql>

4. Now you use Mysql Database.

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

5. Now you run following query to reset fogotten mysql root passwod.

 mysql> update user set password =PASSWORD(“system@123”) where user=’root’;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 2  Changed: 0  Warnings: 0

6.  Now flush privileges and quit from MySQL.

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye
[root@localhost ~]#

7. Now Restart MySQL service.

[root@localhost ~]# service mysqld restart
150403 10:11:16 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
Stopping mysqld:                                           [  OK  ]
Starting mysqld:                                            [  OK  ]
[1]+  Done                    /usr/bin/mysqld_safe –skip-grant-tables

Or

[root@localhost ~]# /etc/rc.d/init.d/mysqld restart
150403 10:11:16 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
Stopping mysqld:                                           [  OK  ]
Starting mysqld:                                            [  OK  ]
[1]+  Done                    /usr/bin/mysqld_safe –skip-grant-tables

Now enjoy.

[root@localhost ~]# mysql -uroot -psystem@123
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

mysql>

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 )

Google+ photo

You are commenting using your Google+ 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 )

w

Connecting to %s