In case if you have forgotten your root password used in MySQL, don’t worry, here is a simple and easiest solution for you. Btw, I’m testing this on my Ubuntu machine. I am not sure if this method will work on other linux distribution.
Firstly you need to stop mysql service running at the backround. Open your terminal then type following command
sudo /etc/init.d/mysql stop
Start the mysqld demon process using the
--skip-grant-tables option with this command
sudo mysqld --skip-grant-tables & mysql -u root mysql
Change root password using this command ( change ‘yournewpassword’ to your desired secure password )
UPDATE user SET Password=PASSWORD('yournewpassword') WHERE User='root'; FLUSH PRIVILEGES; exit;
Now your root password already set. You need to restart the mysql service with this command.
sudo /etc/init.d/mysql start