Home  >  Article  >  Database  >  Modify mysql password command

Modify mysql password command

王林
王林Original
2023-05-20 10:20:072855browse

MySQL is a relational database management system widely used for data storage and management of websites and applications. For database security, it is very important to set a correct and secure password. In MySQL, changing a password is a fairly simple task that only requires a few simple steps and a few commands. This article will introduce in detail how to change the MySQL password through commands.

1. Make sure you are connected to MySQL

Before changing the MySQL password, you must first make sure you are connected to MySQL. You can connect to MySQL through the following command:

mysql -u root -p

This command will open the MySQL command line interface and prompt for a password. After entering the password, press Enter to enter MySQL.

2. Check the current MySQL password

Before changing the MySQL password, you first need to check the currently used password. You can view the current MySQL password through the following command:

SELECT User, Host, Password FROM mysql.user WHERE User = 'root';

This command will list the user named "root" and related information, including the password. If you need to see another user's password, simply replace "root" with the desired username.

3. Modify MySQL password

After viewing the current MySQL password, you can then modify the MySQL password through the following command:

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

In this command, "root " is the user name whose password you want to change, and "localhost" is the host name whose password you want to change. You can change it as needed. "new_password" is the new password, please make sure to change it to a strong password that contains uppercase and lowercase letters, numbers, and special characters.

If you want to modify the host name and password of the current user at the same time, please use the following command:

ALTER USER CURRENT_USER()@'localhost' IDENTIFIED BY 'new_password';

This command will modify the host name and password of the current user (that is, the user connected to MySQL).

4. Refresh MySQL permissions

After the MySQL password is modified, you need to use the following command to update the permissions:

FLUSH PRIVILEGES;

This command will refresh the MySQL permissions to ensure the new password In force.

5. Exit MySQL

After changing the password, you need to use the following command to exit MySQL:

exit;

This command will close the MySQL command line interface.

Summary:

In MySQL, changing the password is very important. It can be done with a few simple steps and a few commands. First you need to make sure you are connected to MySQL and then view your current MySQL password. Then, use the ALTER USER command to change the MySQL password, refresh the MySQL permissions to ensure that the new password has taken effect, and finally use the exit command to exit MySQL. Through the method introduced in this article, you can easily change the MySQL password and enhance the security of the database.

The above is the detailed content of Modify mysql password command. 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