In Linux systems, MySQL database is one of the commonly used open source databases. For MySQL database administrators, ensuring database security is very important. Therefore, it is necessary to change the MySQL password regularly. This article will introduce how to change the MySQL password in the Linux operating system.
First, you need to log in to MySQL as the root user. Enter the following command in the terminal:
sudo mysql -u root -p
You will then be asked to enter the password for the MySQL root user. Enter the correct password and press Enter.
After successfully logging in to MySQL, you can use the following command to modify the MySQL password:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';
Replace the "new password" above for the new password you want to set. Please note that in MySQL, passwords must be at least 8 characters and contain special characters, uppercase letters, lowercase letters, and numbers.
If you want to use columns other than username and hostname in the user table used to save MySQL passwords, replace "localhost" above with the appropriate hostname or IP address.
After completing the password change, you need to refresh the MySQL permission table. Enter the following command:
FLUSH PRIVILEGES;
After completing the password modification and refreshing the permission table, please close MySQL. Enter the following command in the terminal:
exit
and then press Enter to exit MySQL.
Now you can test whether the MySQL password works. Enter the following command in the terminal:
mysql -u root -p
Then enter your new password and press Enter.
If you successfully log in to MySQL, it means that the new password has taken effect.
Summary
This article introduces how to change the MySQL password in the Linux operating system. This is one of the important measures to ensure database security. It is recommended to change the MySQL password regularly. Be sure to remember your new password to ensure security.
The above is the detailed content of Linux changes mysql password. For more information, please follow other related articles on the PHP Chinese website!