How to Change MySQL Root User Password  Linux ubuntu using Command Line

How to Change MySQL Root User Password Linux ubuntu using Command Line

Change Mysql root user password using the command line ubuntu; Through this tutorial, you will learn how to change the Mysql user or root user password on Linux ubuntu using the command line.

How to Reset / Change MySQL User Password Command Line Linux ubuntu

By using the following steps, you can reset or change the MySQL user password on Linux ubuntu using the command line:

  • Step 1 – Login to the MySQL shell as a root
  • Step 2 – Set the MySQL user password
  • Step 3 – Start MySQL Server
  • Step 4 – Verify the new password

Step 1 – Login to the MySQL shell as root

First of all open the command prompt and execute the following command into the command line to access the MySQL root user:

mysql -u root -p

Step 2 – Set the MySQL user password

Execute the following commands on the command line or terminal to change MySQL 8.0 user password on the Linux Ubuntu system:

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

Replace new_password with your own password:

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

Step 3 – Start MySQL Server

Execute the following command on the command line or terminal to restart start MySQL server:

sudo systemctl start mysql

Step 4 – Verify the new password

Execute the following command on the command line to verify that the new password has been applied correctly type:

Login to MySQL using the new password.

sudo mysql -u root -p

Enter the new password you set before when prompted.

Conclusion

Through this tutorial, you have learned how to change or reset the Mysql user password on Linux Ubuntu 22.04 using the command line.

Recommended Linux Ubuntu Tutorials

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

Your email address will not be published. Required fields are marked *