Home  >  Article  >  Database  >  mysql root password modification

mysql root password modification

王林
王林Original
2023-05-08 16:56:37770browse

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.

  1. Enter MySQL

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.

  1. Change Password

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.

  1. Refresh permissions

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;
  1. Exit MySQL

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!

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