How to reset MySQL root password on Linux Debian 11.3

To Reset MySQL Root Password On Debian 11.3

Introduction:

MySQL is a well-known open-source relational database management system developed, distributed, and supported by Oracle Corporation which is used with PHP.

Procedure:

Step 1: Check the installed version of OS by using the below command

[root@linuxhelp ~]# lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux 11 (bullseye)
Release:        11
Codename:       bullseye
No LSB modules are available.

Step 2: Try to login MySQL as root user by using the below command

[root@linuxhelp ~]# mysql -u root -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
Notes: am Forget my mysql password

Step 3: Check the status from MySQL Service by using the below command

[root@linuxhelp ~]# systemctl status mysql
MySQL. Service - MySQL MySQL community-server
     Loaded: loaded (/lib/system/system/MySQL. Service; enabled; vendor preset: >
     Active: active (running) since Wed 2022-05-25 03:04:30 IST; 1 day 2h ago
       Docs: man: MySQL(8)
             https://mysql.com/kb/en/library/systemd/
   Main PID: 782 (MySQL)
     Status: "Taking your SQL requests now..."

Step 4: Stop MySQL Service by using the below command

[root@linuxhelp ~]# systemctl stop mysql

Step 5: Check the status from MySQL Service by using the below command

[root@linuxhelp ~]# systemctl status mysql
MySQL. Service - MySQL community-server
     Loaded: loaded (/lib/system/system/MySQL. Service; enabled; vendor preset: >
     Active: Inactivate (dead) since Wed 2022-05-25 03:04:30 IST; 1 day 2h ago
       Docs: man: MySQL(8)
             https://mysql.com/kb/en/library/systemd/
   Main PID: 782 (MySQL)
     Status: "Taking your SQL requests now..."

Step 6: Run the below command to bypass MySQL authentication by using the below command

[root@linuxhelp ~]# mysqld --skip-grant-tables --user=mysql &
[1] 34275

Step 7: Login MySQL server as a root user by using the below command

[root@linuxhelp ~]# mysql -u root 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Server version: 8.0.26 Source distribution

Step 8: Flush the Privileges by using the below command

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

Step 9: Alter the password for root user by using the below command

mysql> alter user 'root'@'localhost' identified by 'Linuxc#9';
Query OK, 0 rows affected (0.01 sec)

Step 10: Quit MySQL server by using the below command

mysql> \q
Bye

Step 11: Check the MySQL Background process by using the below command

[root@linuxhelp ~]# ps -aux

root         190  0.0  0.0      0     0 ?        S    18:02   0:00 [irq/27-pciehp]
root         191  0.0  0.0      0     0 ?        S    18:02   0:00 [irq/28-pciehp]

root         192  0.0  0.0      0     0 ?        S    18:02   0:00 [irq/29-pciehp]
root         193  0.0  0.0      0     0 ?        S    18:02   0:00 [irq/30-pciehp]
root         194  0.0  0.0      0     0 ?        S    18:02   0:00 [irq/31-pciehp]
root       35289  0.0  0.0      0     0 ?        I    18:27   0:00 [kworker/0:0-events_power_efficient]
mysql      34275  0.8 10.0 1814108 382488 pts/1  Sl   18:28   0:01 mysqld --skip-grant-tables --user=mysql
root       35695  0.0  0.0   7316   908 ?        S    18:30   0:00 sleep 60
root       35732  0.0  0.1  61660  4112 pts/1    R+   18:30   0:00 ps -aux

Step 12: Kill The MySQL Background process by using process id

[root@linuxhelp ~]# kill -9 34275
[1]+  Killed                  mysqld --skip-grant-tables --user=mysql

Step 13: Start the MySQL service by using the below command

[root@linuxhelp ~]# systemctl start mysqld

Step 14: Check the status from MySQL Service by using the below command

[root@linuxhelp ~]# systemctl status mysql
MySQL. Service - MySQL MySQL community-server
     Loaded: loaded (/lib/system/system/MySQL. Service; enabled; vendor preset: >
     Active: active (running) since Wed 2022-05-25 03:04:30 IST; 1 day 2h ago
       Docs: man: MySQL(8)
             https://mysql.com/kb/en/library/systemd/
   Main PID: 782 (MySQL)
     Status: "Taking your SQL requests now..."

Step 15: Login MySQL as a root user by using the below command

[root@linuxhelp ~]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8

Step 16: Flush the privileges by using the below command

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

Step 17: Quit

mysql>\q
Bye

Conclusion:

We have reached the end of this article. In this guide, we have walked you through the steps required to Reset MySQL Root Password on Debian 11.3. Your feedback is much welcome.

FAQ
Q
What kind of Database is MySQL?
A
Mysql is a relational database system.
Q
What is the current stable version of MySQL?
A
The latest stable version of MySQL is 8.0.29
Q
How to backup the table in a database?
A
To backup the table in a database use mysqldump -u root -p database_name table_name > filename.sql
Q
Can we customize the data directory path in MySQL?
A
yes, we can change it by editing the MySQL configuration file.
Q
Is it possible to reset Root's password in Mysql?
A
yes, it is possible to reset Root's password in Mysql.