Friday, July 8, 2011

How to reset mysql root password in linux | Fedora | Redhat

Using the below simple steps, you can reset your mysql root password.

1) Stop mysql server:
#service mysqld stop

2)Start mysql server in safe mode:
Now you have to start the mysql in safe mode with the following option
#mysqld_safe --user=mysql --skip-grant-tables --skip-networking &

3)Login to mysql server without password:
Now you have to login to mysql server without password Using mysql Root User
#mysql -u root mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.47 Source distribution
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>

4)Reset mysql root password:
Run the below command without any mistake ( semicolon is a must )
mysql> UPDATE user SET Password=PASSWORD(‘newrootpassword’) WHERE User=’root’;
mysql> flush privileges;
mysql> exit


5) Restart mysql server:
#service mysqld restart

6) Login to MySQL With the New Password:
root@server ]# mysql -u root -p
Enter password:
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>