Use the following steps to reset a MySQL root password by using the command line interface.
(Ubuntu and Debian) Run the following command"
sudo /etc/init.d/mysql stop
(CentOS, Fedora, and Red Hat Enterprise Linux) Run the following command:
sudo /etc/init.d/mysqld stop
sudo mkdir -p /var/run/mysqld
sudo chown mysql:mysql /var/run/mysqld
Run the following command. The ampersand (&) at the end of the command is required.
sudo mysqld_safe --skip-grant-tables &
Run the following command:
mysql -uroot
Run the following command:
use mysql;
update user set authentication_string=PASSWORD("newPasswordHere") where User='root';
update user set plugin="mysql_native_password" where User='root';
flush privileges;
quit;
mysql -u root -p