Change a Password for MySQL on Linux via Command Line

Reading Time: 2 minutes

Data security is essential to developers, business owners, and system administrators. A vital element of securing data is password management. This guide will teach you how to change a MySQL password in Linux using the command line.


  • A server running CentOS or AlmaLinux.
  • Root-level access to the server.
Change a Password for MySQL on Linux via Command Line

How to Change a MySQL Password on Linux via Command Line

Step 1:

Log into the MySQL server from the command line with the following command.

mysql -u root -p

This command specifies the root user with the -u flag, and the -p flag is for MySQL to prompt for a password. Enter your current password to complete the login.

Step 2:

Switch to the appropriate MySQL database with the following command.

use mysql;

Step 3:

Next, update the password for all MySQL users with the name root. Replace your_new_password with your new password. You can change the password for any user with this command by specifying the username in place of the word root.

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

Step 4:

Finally, reload the privileges with the following command.

flush privileges;

Step 5:

Once all steps are completed, exit MySQL.


Wrapping Up

Completing the MySQL password change in the Linux command line helps administrators manage passwords effectively. Mitigating the risk of security breaches by managing passwords adds yet another layer of security to your arsenal.

If you are looking for a Linux server for your new or existing project, Liquid Web offers VPS Hosting, Cloud Dedicated Servers, and Dedicated servers to fit your needs. Sophisticated hosting options are also available for more complex environments. Contact our sales team today to get started. 

Series Navigation
Next Article >>
Avatar for Ronald Caldwell

About the Author: Ronald Caldwell

Ron is a Technical Writer at Liquid Web working with the Marketing team. He has 9+ years of experience in Technology. He obtained an Associate of Science in Computer Science from Prairie State College in 2015. He is happily married to his high school sweetheart and lives in Michigan with her and their children.

Latest Articles

Controlling PHP settings with a custom php.ini file

Read Article

How to install Puppet Server on Linux (AlmaLinux)

Read Article

Email security best practices for using SPF, DKIM, and DMARC

Read Article

Linux dos2unix command syntax — removing hidden Windows characters from files

Read Article

Change cPanel password from WebHost Manager (WHM)

Read Article