Troubleshooting MySQL Root User Password Setting on macOS
You may have followed the steps to set your MySQL root user password:
However, upon attempting to connect with ./mysql -u root, you find that you can enter the MySQL command line without a password.
Reason:
The issue may arise due to the MySQL privilege mechanism. After modifying the root password, the MySQL privilege tables have not been refreshed.
Solution:
To update the privilege tables and ensure the new password is applied:
For MySQL Versions 5.7 and Up:
mysql> USE mysql; mysql> UPDATE user SET authentication_string=PASSWORD("your_password") WHERE User='root'; mysql> FLUSH PRIVILEGES; mysql> quit
For MySQL Versions 8.0 and Up:
mysql> `ALTER USER 'root'@'localhost' IDENTIFIED BY 'your_password';`
After following these steps, you should be able to connect to MySQL using the specified password.
The above is the detailed content of Why Doesn't My New MySQL Root Password Work on macOS?. For more information, please follow other related articles on the PHP Chinese website!