MySQL is a widely used relational database management system that can be used in many different types of applications. When you set up MySQL, you set up a user and password to access the database. But what if you want to change an existing user's password? In this article, we will introduce how to change user password in MySQL.
First, you need to log in to MySQL. You can use the command line or the graphical interface. If you are using the command line, open a terminal and enter the following command:
mysql -u 用户名 -p
Replace "username" with the username you want to log in with. You will be asked to enter your password. When entering the password, you will not see any characters displayed. This is to protect the password.
After logging in to MySQL, you need to select the database for which you want to change the password. You can use the following command to select a database:
use 数据库名;
Replace "database name" with the name of the database you want to select.
Now, you can use the following command to change the user password:
UPDATE mysql.user SET authentication_string=PASSWORD('新密码') WHERE User='用户名';
Replace "new password" with the one you want to set New password, replace "username" with the username whose password you want to change. After modification, you need to use the following command to refresh the permissions:
FLUSH PRIVILEGES;
After completing the modification of the user password, you can use the following command to exit MySQL:
exit;
The above are the simple steps to change the user password in MySQL. Note that if you have multiple databases, you need to change the password in each database separately. Remember to keep your passwords secure and change them regularly to ensure the security of your database.
Summary
It is not difficult to change user passwords in MySQL. Simply use the command line or graphical interface to select the database and use the UPDATE statement to change the password. Remember to change your password regularly to keep your database secure.
The above is the detailed content of mysql change user's password. For more information, please follow other related articles on the PHP Chinese website!