Change a Password for MySQL on Linux via Command Line
- Change a Password for MySQL on Linux via Command Line
- Create a MySQL Database on Linux via Command Line
- MySQL Select Database on Linux Via Command Line
- How to Backup a MySQL Database: Complete Guide
- Delete a MySQL or MariaDB Database via Command Line
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.
Prerequisites
- A server running CentOS or AlmaLinux.
- Root-level access to the server.

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.
quit
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.
Related Articles:
- Using MySQL Command Line to Create a User
- How to Use Disk Quotas in Dedicated Linux Servers With cPanel
- How to Use Disk Quotas in Dedicated Linux Servers with Plesk
- Remove a MySQL User on Linux via Command Line
- Remove Permissions for a MySQL User on Linux via Command Line
- Grant Permissions to a MySQL User on Linux via Command Line

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.
Our Sales and Support teams are available 24 hours by phone or e-mail to assist.
Latest Articles
2024 cPanel and Plesk pricing breakdown
Read ArticleCentOS Linux 7 EOL — everything you need to know
Read ArticleHow to install Node.js on Linux (AlmaLinux)
Read ArticleUpgrading or installing PHP on Ubuntu — PHP 7.2 and Ubuntu 22.04
Read ArticleWhy is your IP blocked?
Read Article