Despite following the typical steps to set the MySQL root user password, you may encounter an issue where you can access the MySQL command line without entering a password. This can be resolved by following specific commands.
First, execute the following command immediately after logging into the MySQL terminal:
FLUSH PRIVILEGES;
If that doesn't work, execute the following set of commands:
mysql -u root mysql> USE mysql; mysql> UPDATE user SET password=PASSWORD("NEWPASSWORD") WHERE User='root'; mysql> FLUSH PRIVILEGES; mysql> quit
Replace "NEWPASSWORD" with your desired password. This should reset the password effectively.
For MySQL versions 5.7 and up, the "password" field has been renamed to "authentication_string." To update the password in these versions, use the following query:
mysql> UPDATE user SET authentication_string=PASSWORD("NEWPASSWORD") WHERE User='root';
In MySQL 8.0 and above, instead of using the command:
mysql> UPDATE mysql.user SET authentication_string='password' WHERE User='root';
Which overwrites the authentication_string with plain text, use:
mysql> `ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';`
By following these steps, you can effectively set and reset the MySQL root user password, ensuring secure access to your MySQL database.
The above is the detailed content of How Do I Securely Set and Reset the MySQL Root User Password on OS X?. For more information, please follow other related articles on the PHP Chinese website!