Oops! forgot your MySQL root user password. No need of panicking. There are ways through which one can retrieve the password. Just try to follow the below mentioned steps. This has worked for me in a RHEL 8.
1. Login as root user to your machine.
2. Stop/Kill all the mysql daemon/processes.
[root@localhost root]# kill -9 `ps aux | grep mysql | cut -c10-14`
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> exit;
[root@localhosthost root]# kill -9 `ps aux | grep mysql | cut -c10-14`
5. Restart MySQL daemon again.
Viola, you are able to login as the root user to the MySQL database.
Leave a Reply