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.

Prerequisites

  • 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.

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. 

Series Navigation
Next Article >>

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

Onboard to Liquid Web: A Step-By-Step Guide to Migrating Your Data to a Virtual Server

Read Article

Onboard to Liquid Web: A Step-By-Step Guide to Migrating Your Data to a Virtual Server

Read Article

Onboard to Liquid Web: A Step-By-Step Guide to Migrating Your Data to a Virtual Server

Read Article

How to Manage Windows Server Update Settings via Group Policy Editor

Read Article

How to Upgrade Apache and PHP With cPanel’s EasyApache

Read Article