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.
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
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.
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';
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.
After changing the root password of MySQL, you should refresh the permissions of MySQL. To refresh permissions, execute the following SQL command:
FLUSH PRIVILEGES;
After completing the password change and permission refresh, use the following command to exit MySQL:
EXIT;
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:
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!