How to Change MySQL User Password Command Line

How to Change MySQL User Password Command Line

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

How to Change MySQL User Password Command Line

Use the following steps to change the MySQL user password on Linux ubuntu 22.04 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 to change MySQL 8.0 user password on 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 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, we have learned how to change 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.