If you are using Linux and ever lose your MySQL root password or never set a root password and are now unable to access it, so don’t worry, there is an easy way to reset the MySQL root password. On all the modern Linux distributions you can recover the MySQL root password in just a few easy steps.
1. Stop all the MySQL Processes
On Ubuntu and Debian distributions.
service mysql stop
On CentOS, Fedora, and RHEL distributions.
service mysqld stop
2. Start MySQL Server with Safe Mode
mysqld_safe --skip-grant-tables &
3. Connect to the MySQL Server
mysql -u root
4. Setup a New MySQL Root Password
use mysql;
update user set password=PASSWORD("YourNewPassword") where User='root';
flush privileges;
exit
5. Stop MySQL Server and Start MySQL
On Ubuntu and Debian distributions.
service mysql stop
service mysql start
On CentOS, Fedora, and RHEL distributions.
service mysqld stop
service mysqld start
Now you can test your new MySQL root password via logging in to it normally.
mysql -u root -p
After entering the above command, you will be prompted for a new MySQL root password. You can verify whether it is working or not in the shell.
This way you can reset the MySQL root password and make it accessible again.
Leave a Reply