25th Anniversary Savings | 25% Off Dedicated Servers*Shop Now
25th Anniversary Savings | 25% Off VPS Hosting* †††Shop Now
Dedicated Hosting Deals | From $99/moShop Now
Earn hosting credits and a chance to win an Amazon gift card when you refer friends to Liquid Web!Read our promo rules

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

How to Install Adminer MySQL Database Management Tool on AlmaLinux

Read Article

What is CGI-Bin and What Does it Do?

Read Article

Top 10 Password Security Standards

Read Article

Top 10 Password Security Standards

Read Article

How to Use the WP Toolkit to Secure and Update WordPress

Read Article