Jump to content

How to Reset root password in MariaDB 11.xx/10.xx and Mysql 8.0

Featured Replies

Posted
comment_119

In this tutorial I’ll provide you the steps to reset root password for MySQL 8.0 and MariaDB 10.4/10.xx/11.xx 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 mariadb mysql
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 or "ctrl+c" > to get the shell again

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

mysql
FLUSH PRIVILEGES;


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

or

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 mysql mysqld mariadb && systemctl start mysql mysqld mariadb
service mysqld stop && service mysqld restart

some time mysql/mariadb process are still running you need to kill them manually you can find the process via top command : top -u mysql

if it is running then you need to kill the pid with kill -9 "pid no." and restart mysql/mariadb

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:

Quote

/root/.my.cnf
/usr/local/cwpsrv/htdocs/resources/admin/include/db_conn.php

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now