Spotlight

Case Study Microsoft

How Microsoft scaled global content delivery

Find out how Microsoft used Gcore to strengthen delivery across regions.

case study ProSieben GNTM app TOPSHOT

How ProSieben scaled GNTM's app TOPSHOT

Explore how ProSieben brought real-time AI portraits to GNTM's audience.

case study Higgsfield

How Higgsfield scaled AI video generation

See how Gcore helped Higgsfield scale with GPUs and Managed Kubernetes.

case study Fawkes Games

How Fawkes Games stopped DDoS attacks

See how Gcore protected gaming servers from massive DDoS threats without disrupting gameplay.

We're hiring

Help build the next chapter of the web

We're not just filling seats. We're building a team that will write the next chapter of the internet.

  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

Secure data server connected to cloud and other servers, illustrating data management and security.
What Is a High Availability Server?

Every minute your servers are down, your business is bleeding. For e-commerce sites, healthcare platforms, and revenue-critical applications, an outage isn't just an inconvenience. It's a direct hit to your bottom line, your reputation, and

Visual comparison of cloud-based infrastructure connected to devices versus traditional server racks.
Cloud vs Dedicated Server: Which Is Right for You?

Your server choice could be quietly costing you, or quietly holding you back. Pick the wrong infrastructure for your workload and you're either overpaying for idle hardware every month or watching your site buckle under traffic spikes you c

VPS vs Dedicated Server
VPS vs Dedicated Server: Which One Do You Need?

Your site is humming along fine, until it isn't. Traffic spikes, page loads crawl, and your hosting plan buckles under pressure right when it matters most. Choosing between a VPS and a dedicated server isn't just a technical checkbox. It's

Illustration of cloud computing infrastructure, data storage, network security, and digital services.
Multi-Cloud Plan: What It Is and How It Works

Your cloud provider goes down. Applications fail. Customers can't access your services. And because you've built everything around a single vendor, there's nothing you can do but wait. For organizations locked into one cloud platform, this

Padlocked cloud secured with chains, representing digital data protection and cybersecurity measures.
Vendor Lock-In in Cloud Computing: What It Is and How to Avoid It

Imagine discovering that migrating your company's data to a new cloud provider will cost hundreds of thousands of dollars in egress fees alone, before you've even touched the re-engineering work. Or worse, picture being in Synapse Financial

Secure cloud computing infrastructure protecting data, with people, servers, and government institutions.
What Is Sovereign Cloud and Why Does It Matter?

Picture this: a foreign government issues a legal order forcing your cloud provider to hand over sensitive patient records, classified research data, or critical national infrastructure details. You can't stop it. This isn't hypothetical. G

Subscribe to our newsletter

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