Home > Database > Mysql Tutorial > body text

Change the password of mysql user

WBOY
Release: 2023-05-12 11:10:08
Original
973 people have browsed it

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
Copy after login

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 [数据库名称];
Copy after login

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 '[新密码]';
Copy after login

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 '[新密码]';
Copy after login

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;
Copy after login

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!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template