Home Linux How To Reset MySQL Root Password on Debian/Ubuntu & CentOS

How To Reset MySQL Root Password on Debian/Ubuntu & CentOS

537
0

On this tutorial we will guide you how to reset MySQL root password on Fedora/RHEL/CentOS and Debian/Ubuntu server. This guide should work well on MySQL 5.5, MySQL 5.6, MySQL 5.7 and later versions.

In certain conditions it may require us to reset the MySQL root password, for example we want a stronger MySQL root password or maybe you forgot your MySQL database server root password. The main purpose clearly to strengthen our MySQL server database system, make it more secure.

To reset MySQL root password on your server, you can follow this tutorial. This is very easy to do, as long as you have root privileges on your Linux server. Just follow the guide below to change your MySQL root password.

1.) First of all, start your MySQL database server in safe mode. Just run the following simple command

$ mysqld_safe --skip-grant-tables &

2.) After MySQL safe mode is active, you can now login to the MySQL database server without a root password via the SSH terminal. This is very useful if you currently forget your MySQL root password.

$ mysql -u root mysql

3.) Now let’s reset your MySQL root password

For MySQL 5.5 and MySQL 5.6

$ update user set password=PASSWORD("newrootpassword") where User='root';

For MySQL 5.7+

$ mysql> use mysql;
$ mysql> show tables;
$ mysql> describe user;
$ update user set authentication_string=password('newrootpassword') where user='root';

Note: Please replace newrootpassword with the actual new root password for your MySQL database server

READ:  How To Upgrade MariaDB v5.5 to MariaDB v10.4 on VestaCP CentOS 7.7

4.) Run the flush privileges command and exit from the MySQL database server

$ FLUSH PRIVILEGES;
$ quit

5.) Now we need to exit from MySQL safe mode, so we need to shutdown the MySQL database server.

$ mysqladmin -u root -p shutdown

6.) Start your MySQL database server in normal mode as before

* For Debian/Ubuntu server

$ service mysql start or /etc/init.d/mysql start

For Fedora/RHEL/CentOS

$ service mysqld start or /etc/init.d/mysqld start

7.) As for Debian 8+, Ubuntu 14.04+ and CentOS 7 up to the latest version, you can use the systemctl command to start/stop/restart your database server. For example:

On Debian 8/9/10 and Ubuntu 14.04/16.04/18.04/19.04 LTS

$ systemctl restart mysql

On CentOS 7+

$ systemctl restart mysqld.service

LEAVE A REPLY

Please enter your comment!
Please enter your name here