CentosControl PanelCWPLinuxMySQLUbuntuVesta CP

How to Reset root password in MariaDB 10.5/10.4 and Mysql 8.0

In this tutorial I’ll provide you the steps to reset root password for MySQL 8.0 and MariaDB 10.4 easily and efficiently. Since this are latest version of MySQL and fork mariadb you should do some extra caution during root password reset. Below are the easy steps to reset the root password.

If you’re getting below error then it seems root password is not working or something bad happens to MySQL root user :

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

Lets get started with MySQL/mariadb root password reset :-

First stop the MySQL/Mariadb service :

systemctl stop mysqld / systemctl stop mariadb
service mysqld stop / service mariadb stop

Then you need to run the below command to start mysql with skip-grant-tables option :

mysqld --skip-grant-tables --user=root &

if upper user with root not work you can use below with mysql

mysqld --skip-grant-tables --user=mysql &

After running the above command press “Enter” Key > to get the shell again

Then you need to run mysql command and then run flush privileges command under MySQL CLI:


Then at last change the MySQL/Mariadb root password :

ALTER USER 'root'@'localhost' IDENTIFIED BY 'root_passowrd';

Replace “root_password” with some password.

then exit from MySQL cli by typing “quit

Then run this command to kill all mysql processes :

killall -u mysql


pkill -U mysql

Ensure by running this command to unset environments if you accidentally set any :

systemctl unset-environment MYSQLD_OPTS

Now Stop and restart mysql

systemctl stop mysqld.service && systemctl restart mysqld.service
service mysqld stop && service mysqld restart

Thats it you’re done with root password reset for MySQL

Check by logging into mysql root.

CWP and for other control panels only :
On control panel like cwp and other panel having /root/.my.cnf ensure you’ve updated the file with new root password which you changed it via upper command

For CWP only update the new password in this files:


Sandeep B.

I'm a system admin and php developer and currently working as System Admin In CWP Control panel, expertise in Linux and Windows administration RHEL certified admin.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button