Reset Mysql Root Password

Confirm MySQL version

Check MySQL version by running:

If on MySQL version 8, you will see something like:

Restart MySQL with skip-grant-table

To skip the grant tables and reset the root password, we must first stop the MySQL service

Ensure the directory /var/run/mysqld exists

Ensure the directory is own by mysql

Now start MySQL with the --skip-grant-tables option. The & is required here.

The input will be something similar

Press ENTER to return to the bash prompt

Change MySQL Root Password

You can now log in to the MySQL root account without a password

Once logged in, you will see the mysql> prompt

For MySQL 8 on Ubuntu, run following commands

Then run

Replace your_password_here with your own

Run again

Exit MySQL.

Test Root Password

Make sure all MySQL processes are stopped before starting the service again

The output will be similar to

Press enter to continue and start mysql

Log in to MySQL again and you should now be prompted for a password.

Enter your MySQL root password. If correct, you should see something like:

That's It!

----------

Home

Linux

Notes

MicroLog

----------

© DarknessCode