Friday, July 22, 2022

How to Reset the MySQL version 8 Root Password on Ubuntu

 

MySQL is an open-source relational database management system and It's by default port 3306

 


Step 1) First stop the MySQL service and create and initiate permission.

$ sudo /etc/init.d/mysql stop
$ sudo mkdir /var/run/mysqld
$ sudo chown mysql /var/run/mysqld



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

$ sudo mysqld_safe --skip-grant-tables&


  • Press ENTER to return to the Linux BASH prompt.



Step 3)  Reset MySQL Root Password.

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


$ sudo mysql --user=root mysql

  • Once you logged in, you will see the mysql> prompt, then run following commands.



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

>
flush privileges;

  • Replace your_password_here with your own. (Generate a strong password here)


>
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_password_here';

> flush privileges;

> exit


Step 4) Now, Test the New Updated Root Password


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


$ sudo killall -u mysql

  • If you see a message similar to below, press ENTER to continue.

 


  •  Start MySQL Service.


$ sudo /etc/init.d/mysql start

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


$ sudo mysql -p -u root

 


 

End !!!

8 comments:

testing