MySQL: change user password

Have you or one of your MySQL users forgotten the password to a MySQL account? It’s very easy to reset a MySQL user password on Linux, and we’ll show you the commands and step by step instructions below.

Changing the MySQL root password is a bit more involved, so we’ve written a separate guide on how to change MySQL root password.

In this tutorial you will learn:

  • How to change MySQL user password

Changing MySQL user password

Changing MySQL user password

Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux disto
Software MySQL 8.0.21
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

Change MySQL User Password

Open a terminal on your machine and follow the steps below.

  1. Start by logging into MySQL as the root user and switch to the mysql database.
    $ mysql -u root -p
    mysql> use mysql;
  2. Switch the user’s password by using the following syntax (replace values where necessary).
    mysql> ALTER USER 'user'@'localhost' IDENTIFIED BY 'new_password';
  3. Lastly, flush privileges and exit MySQL.
    mysql> exit

That’s all there is to it. Make sure the changes worked by trying to login from your shell with the new password.

$ mysql -u username -p


As you can see, changing a user password in MySQL is quite simple. Hopefully you have found this short guide to be helpful.

Comments and Discussions
Linux Forum