Home  >  Article  >  Database  >  How to change mysql password

How to change mysql password

WBOY
WBOYOriginal
2023-05-14 09:00:361126browse

MySQL is a widely used open source database management system with strong performance, reliability and security. When using MySQL, it is often necessary to change the password of the database administrator (or other user) to ensure data security. This article will introduce how to change user passwords in MySQL.

  1. Login to MySQL

First, you need to log in to MySQL using the correct credentials. You can log in to MySQL using the following command:

mysql -u USERNAME -p

where USERNAME is your username. After executing the command, MySQL will ask you for your password. Enter the password and press Enter to enter MySQL.

  1. Select the user whose password you want to change

In MySQL, you can use the following command to display the current user:

SELECT user, host FROM mysql.user;

This command will display the current user in MySQL list of users. Select the user whose password you want to change in the list.

  1. Change Password

After you select the user whose password you want to change, you can use the following command to change the password:

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

Where, 'username' and 'host' is the username and host address you want to change the password for, and new_password is the new password you want to set. After executing this command, MySQL will update the user's password.

You can also use the following command to change your own password:

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

Similarly, 'username' and 'host' are the username and host address you want to change the password, and new_password is the password you want to set new password. After executing this command, MySQL will update your password.

  1. Exit MySQL

After you have completed all changes, you can exit MySQL using the following command:

EXIT;

This will exit MySQL and return you to the command line interface.

Summary

MySQL is a powerful database management system that requires regular changes to the administrator password to ensure data security. This article introduces how to change user passwords in MySQL. I hope it will be helpful to you.

The above is the detailed content of How to change mysql password. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:mysql delete recoveryNext article:mysql delete recovery