Home > Database > Mysql Tutorial > body text

mysql password modification linux

王林
Release: 2023-05-08 11:37:38
Original
701 people have browsed it

When using MySQL, the password is a very important part, which ensures the security of the database. However, occasionally situations arise where you need to change your MySQL password. This article will introduce how to change the MySQL password in Linux.

1. Log in to MySQL

In the Linux terminal, use the following command to log in to MySQL:

$ mysql -u 用户名 -p
Copy after login

where the username is your MySQL username, and then in the prompt Enter the password below. If the password is correct, you will enter the MySQL command line prompt.

2. Select the database

Next, select the corresponding database at the MySQL command line prompt. Assuming that the password we want to change belongs to a database named example, you can use the following command to select it:

mysql> use example;
Copy after login

3. Change the password

Now we have logged in to MySQL and selected the correct database , you can start changing your password. There are two ways to change the MySQL password. The first is to use the SET command:

mysql> SET PASSWORD = PASSWORD('新密码');
Copy after login

In this command, enclose the new password in quotes. Passwords must be six or more characters long, and a combination of uppercase and lowercase letters, numbers, and symbols is recommended. When you enter the command, MySQL will immediately change the password to the new password.

The second method is to use the UPDATE command:

mysql> UPDATE mysql.user SET Password = PASSWORD('新密码') WHERE User = ‘用户名’;
mysql> FLUSH PRIVILEGES;
Copy after login

The user name is the MySQL user name you want to change the password. The password rules are the same as above. After executing this command, MySQL will update the password of the corresponding user.

Note: After changing the password, the MySQL privilege table must be refreshed for the change to take effect. The FLUSH PRIVILEGES command will update all changes immediately.

4. Exit MySQL

After completing all the steps, you can use the following command to exit MySQL:

mysql> exit;
Copy after login

Now your MySQL password has been successfully modified.

Summary

The security of MySQL password is very important, so it is necessary to change the MySQL password in Linux. You can use the SET or UPDATE command to modify the password, but be sure to refresh the MySQL privilege table after completing the modification to ensure that all changes take effect.

The above is the detailed content of mysql password modification linux. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!