Home  >  Article  >  Database  >  How to change MySQL database password in CentOS

How to change MySQL database password in CentOS

PHPz
PHPzOriginal
2023-04-04 13:59:151314browse

CentOS MySQL Password Change

MySQL database is a popular relational database management system that provides data storage and management for many websites and applications. In CentOS operating system, MySQL is a very common database. In order to enhance system security, we need to regularly change the access password for the MySQL database. This article will teach you how to change MySQL database password in CentOS.

Step 1: Log in to MySQL

To change the MySQL database password, you need to log in to MySQL first.

The command to log in to MySQL is as follows:

mysql -u root -p

After entering the command, the system will prompt you to enter the MySQL root account password. After entering, press Enter to enter the MySQL environment.

Step 2: Change the password

After entering the MySQL environment, enter the following command to change the password:

ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';

Among them, root is the user name, localhost is the host name, and new_password is The new password to be changed.

After entering the above command, MySQL will change the password of the root user to new_password. If you want to change the password of another username, you only need to replace root in the above command with the corresponding username, and replace localhost with the corresponding hostname.

Step 3: Exit MySQL

After completing the password change, you need to exit the MySQL environment. The command is as follows:

exit

Now you have successfully changed the password of the MySQL database and can log back in to the MySQL environment using the new password.

Summary

It is very simple to change the password of the MySQL database in CentOS. First, you need to log in to MySQL and use the ALTER USER command to modify the username and password. You can then log back into the MySQL environment using your new credentials. By changing your MySQL password regularly, you can effectively improve the security of your password protection and protect your data from the risk of hackers and data leaks.

The above is the detailed content of How to change MySQL database password in CentOS. 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