Reset forgotten MySQL root password
Submitted by ravisagar on Tue, 01/08/2008 - 04:08.If you have forgotten your MySQL root password then don't worry. You can reset your lost password. Here is the procedure.
1. Login as root.
2. Kill running MySQL process and stop the MySQL service.
[root@localhost root]# killall mysqld
[root@localhost root]# /usr/libexec/mysqld -Sg --user=root &
3. Restart MySQL server with these parameters
[root@localhost root]# mysqld --skip-grant-tables --user=root
4. Manually set root password in the table "user" of "mysql" database.
[root@localhost root]# mysql
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 1 to server version: 3.23.41
Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
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
mysql> UPDATE user
-> SET password=password("newpassword")
-> WHERE user="root";
Query OK, 2 rows affected (0.04 sec)
Rows matched: 2 Changed: 2 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> exit;
[root@localhosthost root]# killall mysqld
5. Restart MySQL again
[root@localhosthost root]# /etc/init.d/mysqld start
Now your root password is set and you can now login as root using the password you have just created.
[root@localhost root]# mysql -u root -p
Enter Password: "newpassword"
If you again forget your root password don't worry just check this link again :)
- ravisagar's blog
- Add new comment
- 1024 reads

Recent comments
6 weeks 3 days ago
12 weeks 2 days ago
15 weeks 3 days ago
16 weeks 7 hours ago
16 weeks 9 hours ago
28 weeks 1 day ago
28 weeks 1 day ago
29 weeks 14 hours ago
33 weeks 3 days ago