Home  >  Article  >  Database  >  Linux modify mysql password modification

Linux modify mysql password modification

PHPz
PHPzOriginal
2023-05-08 19:05:081393browse

Change MySQL password under Linux

MySQL is the most popular open source relational database management system in the world. Many websites and applications use it to store and manage data. On Linux systems, MySQL is also a very common database. When using MySQL, we may need to change the MySQL password. For example, when we install MySQL on a new server, the initial password may need to be changed.

In this article, we will introduce how to change MySQL password on Linux system.

Step 1 - Connect to the MySQL server

We need to connect to the MySQL server first before we can change the MySQL password. Use the following command to connect to MySQL:

mysql -u root -p

If you have set a root password before, you need to enter the password. If there is no password, just press the Enter key to log in.

Step 2 - Change password

After successful login, you can use the following command to change the password:

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

Here, replace "root" with the existing user name and "localhost" with the host name of the computer on which MySQL is installed, such as "127.0.0.1" or "localhost". "new_password" is the new password, you can choose it yourself.

If you want to make the password stronger, you can use the following command:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'super_strong_password';

Step 3 - Refresh permissions

After changing the password, you need to refresh the permissions so that the new password can take effect:

FLUSH PRIVILEGES;

Step 4 – Exit MySQL

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

exit

At this point, the steps to change the MySQL password on the Linux system are completed.

Summary

It is easy to change the MySQL password on the Linux system. You only need to log in to MySQL, change the password and refresh the permissions. Please note that to protect database security, you should use strong passwords and grant users only the necessary database permissions. If it is not necessary to log into MySQL using the root user, you should create a user with appropriate permissions.

The above is the detailed content of Linux modify mysql password modification. 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
Previous article:mysql query garbled codeNext article:mysql query garbled code