Home > Database > Mysql Tutorial > How to change mysql password in linux

How to change mysql password in linux

PHPz
Release: 2023-04-17 09:54:42
Original
8623 people have browsed it

Under Linux system, we often need to change the Mysql database password. Mysql database is a very popular database management system and is widely used. Let's take a look at how to change the password of the Mysql database under the Linux system.

Step 1: Log in to Mysql

First, we need to log in to Mysql using the root account. Enter the following command in the terminal:

mysql -u root -p
Copy after login
Copy after login

After pressing the Enter key, the system will prompt you to enter the password of the root account. After entering the correct password, you can log in to the Mysql database.

Step 2: Change password

Once you have successfully logged in to the Mysql database, you can use the following command to change the Mysql password:

USE mysql;
UPDATE user SET authentication_string=PASSWORD('New_password_here') WHERE User='root';
Copy after login

This command will change the root account's password The password is changed to New_password_here. After the modification is completed, you need to update your user permissions and exit Mysql.

FLUSH PRIVILEGES;
QUIT;
Copy after login

Step 3: Verify the new password

Now, you can use the new password to log in to the Mysql database. Enter the following command in the terminal:

mysql -u root -p
Copy after login
Copy after login

When the password prompt appears, enter the new password. If you enter the correct password, you will be able to log in to the Mysql database. Congratulations, you have successfully changed the password of the Mysql database.

Notes

When changing the Mysql password under the Linux system, please pay attention to the following:

  1. These commands only apply to the root account.
  2. If your Mysql database has enabled SSL-consuming database connections, then you need to add the "-ssl" option to the command line.
  3. If your Mysql database has enabled the secure file privileges option, then you need to add the "--secure-file-priv" option to the command line.
  4. Please note that there may be multiple users with root access.
  5. The new Mysql version uses the "authentication_string" field instead of the previous "password" field.

Summary

Now, you already know how to change the password of Mysql database under Linux system. This is very important because Mysql database is a popular database management system, and in During the operation, we need to change the password frequently to improve security. We hope you find these steps helpful so you can better manage your data.

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