Home > Database > Mysql Tutorial > body text

mysql root password change

WBOY
Release: 2023-05-08 12:49:07
Original
1030 people have browsed it

MySQL is currently one of the most popular open source database systems and is widely used in web applications and server-side applications. When using MySQL, it is sometimes necessary to change the root user's password. This article will introduce how to change the MySQL root user password.

  1. Login to MySQL

To change the root password of MySQL, you must first log in to the MySQL server. You can log in using the following command:

mysql -u root -p
Copy after login

This command will ask you to enter the password of the root user, if the password is correct, you will be logged in to the MySQL server.

  1. Execute SQL commands

In MySQL, you can use SQL commands to change the password. To change the root user's password, use the following SQL command:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'new_password';
Copy after login

Where, 'new_password' is the new password you wish to set for the root user. Please note that when copying and pasting this statement into the MySQL terminal, 'new_password' should be replaced with the password of your choice.

  1. Refresh permissions

After changing the root password of MySQL, you should refresh the permissions of MySQL. To refresh permissions, execute the following SQL command:

FLUSH PRIVILEGES;
Copy after login
  1. Exit MySQL

After completing the password change and permission refresh, use the following command to exit MySQL:

EXIT;
Copy after login

At this point, you have successfully changed the MySQL root user password.

Summary

MySQL is a commonly used database management system, and its security cannot be ignored. This article introduces how to change the root user password of MySQL:

  1. Log in to MySQL
  2. Use SQL commands to change the password
  3. Refresh permissions
  4. Exit MySQL

When changing the MySQL root password, please remember to use a strong password and ensure that only necessary users are authorized to access the database.

The above is the detailed content of mysql root password change. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!