Gaming industry under DDoS attack. Get DDoS protection now. Start onboarding
  1. Home
  2. Developers
  3. How to Change User Password in MySQL

How to Change User Password in MySQL

  • By Gcore
  • August 8, 2023
  • 2 min read
How to Change User Password in MySQL

MySQL is one of the most popular and widely-used database systems in the world. Because of its versatile relational database management system, many different types of software and applications utilize it for data storage and management. In MySQL, knowing how to change the user’s password is important. This will allow you to protect sensitive data and ensure that your databases remain secure. In this article, we’ll show you a step-by-step guide on changing your user password in MySQL.

Steps on Changing User Password in MySQL

Changing the user password in MySQL involves understanding the version you’re working with, as different versions might require different commands. Please be aware that you have the required admin privileges to update the password, and there’s no need for any special permissions to continue. Here’s a step-by-step guide to help you through the process.

Note: Before you begin, please remember to replace ‘username’, ‘new_password’, and ‘old_password’ with the actual username and the relevant passwords. Also, ensure you follow best practices for creating secure passwords.

#1 Check the MySQL Version

Open the terminal and log in to MySQL using this command.

mysql -u username -p

You’ll be prompted to enter your password. Once you’re logged in, you can run the following SQL command to see the version:

SELECT VERSION();

The MySQL version will be displayed as the output. You can also check the version without logging into the MySQL shell by running:

mysql --version 

This will display the MySQL client version, along with some other information, directly in your command-line interface.

#2 For MySQL version 5.7.6 or Later

Run the following SQL command to change the password.

ALTER USER 'username'@'localhost' IDENTIFIED BY 'new_password';

#3 For MySQL version before 5.7.6

Use this SQL command to change the password.

SET PASSWORD FOR 'username'@'localhost' = PASSWORD('new_password');

If the two methods mentioned earlier don’t work, you can also use the ‘mysqladmin’ command. Check the next step for details.

#4 Using mysqladmin (Command-Line Tool)

In the command line, run the following command:

mysqladmin -u username -p'old_password' password 'new_password'

#5 Flush Privileges

This ensures that the changes are applied immediately. Run the command below.

FLUSH PRIVILEGES;

You’ve done it! You’ve completed updating your password, enhancing the security of your database. This simple step of changing your password helps protect your MySQL database against potential hacking attempts. It’s an essential measure to ensure that your information remains safe and secure.

Conclusion

Searching for a managed database solution? Choose Gcore Managed Database for PostgreSQL so you can focus on your core business while we manage your database.

  • 99.9% SLA for uninterrupted service with high-availability architecture
  • Adjustable database resources for changing demands
  • Currently in free public beta

Start managing your database

Related articles

What's the difference between multi-cloud and hybrid cloud?

Multi-cloud and hybrid cloud represent two distinct approaches to distributed computing architecture that build upon the foundation of cloud computing to help organizations improve their IT infrastructure.Multi-cloud environments involve us

What is multi-cloud? Strategy, benefits, and best practices

Multi-cloud is a cloud usage model where an organization utilizes public cloud services from two or more cloud service providers, often combining public, private, and hybrid clouds, as well as different service models, such as Infrastructur

What is cloud migration? Benefits, strategy, and best practices

Cloud migration is the process of transferring digital assets, such as data, applications, and IT resources, from on-premises data centers to cloud platforms, including public, private, hybrid, or multi-cloud environments. Organizations can

What is a private cloud? Benefits, use cases, and implementation

A private cloud is a cloud computing environment dedicated exclusively to a single organization, providing a single-tenant infrastructure that improves security, control, and customization compared to public clouds.Private cloud environment

What is a cloud GPU? Definition, types, and benefits

A cloud GPU is a remotely rented graphics processing unit hosted in a cloud provider's data center, accessible over the internet via APIs or virtual machines. These virtualized resources allow users to access powerful computing capabilities

What is cloud networking: benefits, components, and implementation strategies

Cloud networking is the use and management of network resources, including hardware and software, hosted on public or private cloud infrastructures rather than on-premises equipment. Over 90% of enterprises are expected to adopt cloud netwo

Subscribe to our newsletter

Get the latest industry trends, exclusive insights, and Gcore updates delivered straight to your inbox.