As a website operation and maintenance personnel, when we need to manage the MySQL server, we may need to modify the MySQL root password due to security, change and maintenance reasons. But sometimes you forget your password, what should you do? This article explains how to reset the MySQL root password on Linux.
Resetting the MySQL root password on Linux requires the following two steps:
The following are the detailed steps:
Use the following command to stop the MySQL service:
# systemctl stop mysqld
Use the following command to start MySQL, and set it to log in without a password:
# systemctl set-environment MYSQLD_OPTS="--skip-grant-tables" # systemctl start mysqld
Next, use the following command to log in to MySQL:
# mysql -uroot
Since you have set up skip verification using --skip-grant-tables
, MySQL will not ask for input at this time. password.
After successful login, use the following command to modify the password of the root user:
mysql> UPDATE mysql.user SET authentication_string=PASSWORD('newpassword') WHERE User='root';
After modification, execute the following command to refresh MySQL permissions:
mysql> FLUSH PRIVILEGES;
Finally, use the following command to exit MySQL and reset the MySQL service:
mysql> exit; # systemctl unset-environment MYSQLD_OPTS # systemctl restart mysqld
Resetting the MySQL root password on Linux is done. In a production environment, always remember to remove the --skip-grant-tables
prefix from your MySQL configuration to increase database security.
Summary:
This article describes how to reset the MySQL root password on Linux. By using the --skip-grant-tables
prefix when MySQL is started, we can log into MySQL without the root password, thereby resetting the root user's password. In a production environment, it is important to protect the security of MySQL.
The above is the detailed content of How to reset MySQL root password on Linux?. For more information, please follow other related articles on the PHP Chinese website!