Need Assistance?

In only two hours, with an average response time of 15 minutes, our expert will have your problem sorted out.

Server Trouble?

For a single, all-inclusive fee, we guarantee the continuous reliability, safety, and blazing speed of your servers.

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.

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

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.

Prevent your website from Downtimes

Get our experts to manage your server with weekly auditing and 24/7 monitoring

Liked!! Share the post.

Get Support right now!

Start server management with our 24x7 monitoring and active support team

Can't get what you are looking for?

Available 24x7 for emergency support.