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


SUBSCRIBE TO NEWSLETTER
Subscribe to Linux Career NEWSLETTER and receive latest Linux news, jobs, career advice and tutorials.


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> FLUSH PRIVILEGES;
    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

Conclusion

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

FIND LATEST LINUX JOBS on LinuxCareers.com
Submit your RESUME, create a JOB ALERT or subscribe to RSS feed.
LINUX CAREER NEWSLETTER
Subscribe to NEWSLETTER and receive latest news, jobs, career advice and tutorials.
DO YOU NEED ADDITIONAL HELP?
Get extra help by visiting our LINUX FORUM or simply use comments below.

You may also be interested in:



Comments and Discussions