MySQL is an open source relational database management system and one of the important tools in web application development. MySQL requires an authorized user to log in to run. The MySQL root user has the highest authority and can perform any operation on the database, so it is often the focus of attacks by attackers. Therefore, it is very necessary to regularly change the MySQL root user password. This article will introduce how to change the MySQL root password.
First you need to enter MySQL, you can use the following command:
mysql -u root -p
This command will prompt you to enter the password of the root user. If entered correctly, you will enter MySQL.
After entering MySQL, you need to use the following command to change the password:
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpassword');
Among them, newpassword is the new password you want to set. Note the use of single quotes.
If you want the root user to access MySQL from anywhere, not just localhost, you can use the following command:
SET PASSWORD FOR 'root'@'%' = PASSWORD('newpassword');
Similarly, where newpassword is the new password you want to set.
After changing the password, you need to refresh the MySQL permissions to make it effective. You can use the following command to refresh the permissions:
FLUSH PRIVILEGES;
After the modification is completed, you need to use the following command to exit MySQL:
exit;
At this point, MySQL The root user password has been changed.
It should be reminded that it is recommended to set the password to be complex and long enough, and to change the password regularly to increase the security of MySQL.
The above is the detailed content of mysql root password modification. For more information, please follow other related articles on the PHP Chinese website!