Home >Database >Mysql Tutorial >How Can I Properly Set the MySQL Root User Password on OS X?
Setting the MySQL root user password on OS X: Resetting privileges
You have attempted to set the root user password for MySQL on OS X, but you are still able to access the mysql command line without entering a password. This can be rectified by either flushing the privileges or executing a series of commands within the MySQL terminal.
Option 1: Flush privileges
Once logged into the MySQL terminal, simply execute the following command:
FLUSH PRIVILEGES
Option 2: Execute MySQL commands
Enter the following series of commands in the MySQL terminal:
mysql -u root mysql> USE mysql; mysql> UPDATE user SET password=PASSWORD("NEWPASSWORD") WHERE User='root'; mysql> FLUSH PRIVILEGES; mysql> quit
Replace "NEWPASSWORD" with the desired password. This should reset the root user password.
Update for MySQL versions
MySQL 5.7: Replace the "password" field with "authentication_string" in the UPDATE query.
mysql> UPDATE user SET authentication_string=PASSWORD("NEWPASSWORD") WHERE User='root';
MySQL 8.0 and above: Use the ALTER USER command instead to set the password.
mysql> `ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';`
By following these steps, you can successfully set the MySQL root user password and secure your database.
The above is the detailed content of How Can I Properly Set the MySQL Root User Password on OS X?. For more information, please follow other related articles on the PHP Chinese website!