Home >Database >Mysql Tutorial >linux change mysql password

linux change mysql password

WBOY
WBOYOriginal
2023-05-18 11:27:086157browse

When using MySQL, we need to perform various operations on it, such as creating users, authorizing, changing passwords, etc. This article will introduce how to change the password of the MySQL user in the Linux system.

1. Log in to MySQL

To log in to MySQL under Linux, we need to use the following command:

mysql -uroot -p

Among them, root is the super user of MySQL, and -p means that a password needs to be entered. , after logging in we need to enter the password of the MySQL super user.

2. View users

To view all users in MySQL, you can use the following command:

select User from mysql.user;

Among them, mysql.user is the table in MySQL that stores user information. User is one of the fields, and this command will output all users in MySQL.

3. Change the password

If we want to change the password of a user in MySQL, we can use the following command:

update mysql.user set Password=password('新密码') where User='用户名';

Among them, update mysql.user is to update the user information In the statement of the table, Password=password('new password') means that the new password is encrypted and stored in the password field of the user, and User='username' means the username of the user who wants to change the password.

After executing this command, you can use the following command to refresh MySQL user information:

flush privileges;

4. Exit MySQL

After completing the password change, we need to use the following command to exit MySQL :

quit;

This completes the operation of changing the MySQL user password in the Linux system. It should be noted that when changing the MySQL user password, make sure you are logged in as the super user of MySQL, otherwise the change may fail. In addition, it is recommended to set the password of the MySQL user to a strong password to improve the security of the system.

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