How to change MySQL password via Terminal

This tutorial is going to show you how to change a MySQL user password via command line. If you are not familiar with command line, you may use the GUI application such as MySQL Workbench (free) or Navicat premium (commercial). Changing MySQL user’s password via Terminal actually not complicated. With few commands, we can easily change the user’s password.

On this example, I want to change my root password. Please note that root here is not the system root user. This is the MySQL root user.

Steps to change MySQL user’s password via Terminal

First, login to MySQL

mysql -u root -p

You will be asked to enter the root’s password. Next, we need to switch to mysql database inside the MySQL console.

use mysql;

Now its time to update the root password

update user set password=PASSWORD(‘your_new_password’) where User=’root’;

You can change the user with any of your MySQL user. Simply modify the command above.

Now flush the privileges

flush privileges;

Exit MySQL

exit;

Thank you for coming. Please leave us comment if you need any assistance.

Be the first to comment

Leave a Reply

Your email address will not be published.


*