Reset Root Password In MySQL V8

Hisham Moideen

WordPress freelancer

Reset Root Password In MySQL V8

The following method worked for me in MySQL (version 8) running on Ubuntu OS.

Step 1: Check your MySQL version. Open the terminal and run the following command.

    my sql -V

Step 2: Stop MySQL server.

  sudo /etc/init.d/mysql stop

Step 3: Create a directory

  sudo mkdir /var/run/mysqld

To change directory owner,

  sudo chown mysql /var/run/mysqld

Step 4: Start MySQL server

  sudo mysqld_safe --skip-grant-tables &

Step 5: Log in to MySQL without a password.

  sudo mysql --user=root mysql

Step 6: Select user for password reset

  UPDATE mysql.user SET authentication_string=null WHERE User='root';

Step 7: Flush privileges.

  flush privileges;

Step 8: Change root password. Here, replace the new_password with your password.

  ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'new_password';

Step 9: Flush privileges.

  flush privileges;

Step 10: Exit the current session.


Step 11: Stop all the processes.

  sudo killall -u mysql

Step 12: Start MySQL server.

  sudo /etc/init.d/mysql start

Step 13: Log in to MySQL using your new password.

  sudo mysql -p -u root

That’s it, your root password has been changed.