Home  >  Article  >  Database  >  mysql change password linux

mysql change password linux

WBOY
WBOYOriginal
2023-05-08 09:00:36683browse

MySQL is a free and open source relational database management system and one of the most popular databases currently. Under the Linux system, we need to change the MySQL password to ensure the security of the database. The following describes how to change the MySQL password under Linux system.

Step 1: Open the terminal

First, under Linux system, we need to use the terminal to operate. You can open the terminal by pressing the Ctrl Alt T key combination or by finding the terminal in the application.

Step 2: Log in to MySQL

Enter the following command to log in to MySQL:

mysql -u root -p

-u is the username parameter, here we take the root user as an example. The -p parameter indicates that a password is required. After executing this command, the system will prompt you to enter the MySQL password. Enter the correct password to log in to MySQL.

Step 3: Change the password

If you want to change the password of the root user, enter the following command in the terminal:

use mysql;
update user set authentication_string=password('新密码') where user='root';
flush privileges;
quit;

Among them, replace "new password" with your The new password you want to set. After executing this command, your MySQL password has been successfully modified.

If you are not a root user, you can use the following command to change the password:

use mysql;
update user set authentication_string=password('新密码') where user='用户名';
flush privileges;
quit;

Similarly, replace "new password" with the new password you want to set and replace "username" with for your username.

Step 4: Log in to MySQL again

After changing the password, you need to log in to MySQL again for the modification to take effect. Enter the following command in the terminal to log in to MySQL again:

mysql -u root -p

After entering the password of the root user, you can log in to MySQL using the new password.

Summary:

Through the above steps, you can easily change the MySQL password under the Linux system. Please note that only authorized persons can access the database and change passwords regularly to ensure database security.

The above is the detailed content of mysql change password linux. 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