Students question – How to Reset MySQL Root Password?

MySQL root account is very critical. Without it the root user won’t be allowed to access or mange MySQL databases. This brief tutorial shows students and new users steps to reset the root password of MySQL database server.

Losing the root password for your MySQL database server is a show stopper. ¬†You won’t be able to access or manage the server as all. You’ll have to find a way to reset that lost password or you’re out for good.

This brief tutorial shows students how to easily reset forgotten MySQL root password.

Step 1: Step MySQL server

The first step in this process is to stop MySQL server. You won’t be able to reset MySQL root password while the server is running. You need to temporarily stop it by running the commands below.

Ubuntu: sudo systemctl stop mysql
Other systems: sudo systemctl stop mysqld

Step 2: Start MySQL server in safe-mode to bypass security protocols

Next, start MySQL server with the options to skip-grant-tables. In this mode, you will be able to login to the default MySQL database and create a new password for the root user.

To do that, run the commands below.

sudo mysqld_safe --skip-grant-tables &

Step 3: Login to MySQL database

Next, login to MySQL database server into MySQL default database. To do that, run the commands below.

mysql -u root mysql

Step 4: Create a New root password

Finally, run the SQL statements below to create a new password for the root user.

UPDATE USER SET authentication_string=password('new_password_here') WHERE USER='root';

FLUSH PRIVILEGES;

exit;

After that, restart MySQL server and you should be good.

sudo systemctl restart mysql

Now you should be able to logon to MySQL server using the new password. Hope this helps and please come back if you like this.

Enjoy!