November 10, 2020

How to Reset MySQL root password in Centos 7


MySQL Is an open-source Relational Database Management System (RDMS). It uses tables, triggers, variables, views, etc. MariaDB is a fork of MySQL. The database structures and indexes of MariaDB are same as the MySQL. This blog covers the steps to reset MySQL root password without any data loss.

Here in Skynats, we had done so many mysql root password reset without any data losses under our server management service.


Click here to get more info about: outsourced server support

Reset root password in Safe Mode


Check MySQL or MariaDB version


mysql --version
mysql Ver 15.1 Distrib 10.3.22-MariaDB, for Linux (x86_64) using readline 5.1


Stop MySQL/MariaDB service


systemctl stop mariadb


Then start MySQL/MariaDB in safe mode without loading the privileges


mysqld_safe --skip-grant-tables --skip-networking &


200306 10:56:59 mysqld_safe Logging to '/var/lib/mysql/mysqltest.err'.
200306 10:56:59 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql


Then connect MySQL/MariaDB as root and run change password query/command

mysql -u root -p

MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword';
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> exit


Next kill/stop the MySQL/MariaDB instance process id

For More Information:aws cloud management 

kill $(cat /var/lib/mysql/mysqltest.pid )

Start MySQL/MariaDB in normal mode


systemctl start mariadb


Now, Login as mysql root user with new password


mysql -u root -p


Password:

You can able to login the MySQL/MariaDB using new root password.