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 above command you will be prompted for new MySQL root password. You can verify it whether it is working or not in the shell.
This way you can reset MySQL root password and make it accessible again.