MySQL is a popular relational database management system that can use a variety of ways to manage users and access permissions. This article will show you how to change the password of a MySQL user.
Step 1: Connect to MySQL
First, you need to connect to the MySQL server. To connect to the MySQL server, open the MySQL client in the terminal and type the following command:
mysql -u [用户名] -p
Please replace "[username]" with a valid username in MySQL. Then, press Enter and enter the user's password. If you already know the user's password, you can skip this step.
Step 2: Select the database
After connecting to the MySQL server, you need to select the database for which you want to change the password. To select a database, use the following command:
USE [数据库名称];
Replace "[database name]" with the name of the database you want to use.
Step 3: Change Password
After selecting the database for which you want to change the password, you can use the following command to change the password of the MySQL user:
ALTER USER '[用户名]'@'localhost' IDENTIFIED BY '[新密码]';
Please replace "[ Replace "username]" with the username of the MySQL user whose password you want to change, and "[new password]" with the new password for that user.
If you want to change the password of a user with global access, use the following command:
ALTER USER '[用户名]'@'%' IDENTIFIED BY '[新密码]';
Please note that in this command, "@'localhost'" is used to specify the Users can only connect to the MySQL server from localhost. If you want to allow this user to connect to the MySQL server from other computers, use "@'%'" instead of "@'localhost'".
Step 4: Refresh permissions
After changing a user's password, you need to refresh the user's permissions. To refresh permissions, use the following command:
FLUSH PRIVILEGES;
This will refresh the MySQL server's permissions table and make the changed password take effect.
Summary
This article shows you how to change user passwords in MySQL. It's a simple process that only requires a few simple commands to complete. You can use the same command to change the password of a user with global access. Always make sure to back up your database before changing the password of any database user to ensure you don't lose any data.
The above is the detailed content of Change the password of mysql user. For more information, please follow other related articles on the PHP Chinese website!