Home > Database > Mysql Tutorial > Linux changes mysql password

Linux changes mysql password

PHPz
Release: 2023-05-08 15:33:39
Original
881 people have browsed it

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.

  1. Login to MySQL

First, you need to log in to MySQL as the root user. Enter the following command in the terminal:

sudo mysql -u root -p
Copy after login

You will then be asked to enter the password for the MySQL root user. Enter the correct password and press Enter.

  1. Modify MySQL password

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

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.

  1. Refresh the MySQL permission table

After completing the password change, you need to refresh the MySQL permission table. Enter the following command:

FLUSH PRIVILEGES;
Copy after login
  1. Close MySQL

After completing the password modification and refreshing the permission table, please close MySQL. Enter the following command in the terminal:

exit
Copy after login

and then press Enter to exit MySQL.

  1. Test MySQL Password

Now you can test whether the MySQL password works. Enter the following command in the terminal:

mysql -u root -p
Copy after login

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!

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