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 -pThis 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.
quitWrapping 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 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.
Ronald Caldwell