Home  >  Article  >  Database  >  linux mysql change password

linux mysql change password

王林
王林Original
2023-05-18 10:47:371929browse

In the Linux operating system, the MySQL database management system is a widely used open source software. It can be used in various scenarios, such as as a backend database for websites or applications. However, during use, you may need to modify the MySQL access password. Next, we will learn how to change the MySQL access password in the Linux operating system.

1. Log in to MySQL

First, we need to log in to MySQL as the root user in order to change the user password. Log in to MySQL using the following command.

mysql -u root -p

You will be prompted for your password. As you enter your password, you won't be able to see the characters you entered, but you can continue typing your password. After entering your password, press Enter to continue.

2. Select the database

After logging in to MySQL, we need to select the database to be modified. You can select a database using the following command.

use databasename;

Please replace "databasename" with the database name you want to choose.

3. Query the user

After selecting the database, we need to query the user to be modified and its password. In order to query users, use the following command.

SELECT user,authentication_string,plugin,host FROM mysql.user;

This command will list all users that exist in the MySQL users table, including username, password hash, plugin information and host information.

4. Change password

Now, we have found the user and password we want to change. In order to change the password, use the following command.

UPDATE mysql.user SET authentication_string=PASSWORD('new_password') WHERE user='user_name' AND Host='Host_name';

Please replace "new_password" with the new password you want to set, "user_name" with the name of the user whose password you want to change, and "Host_name" with the name of the host connected to MySQL.

5. Refresh permissions

After changing the password, you need to refresh the permissions of MySQL to make it effective. Use the following command to refresh the permissions.

FLUSH PRIVILEGES;

Now you have successfully changed your MySQL access password. You can connect to MySQL using the new password and operate against the original user account.

The above is the detailed content of linux mysql change 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