Home >Database >Mysql Tutorial >How Can I Properly Set the MySQL Root User Password on OS X?

How Can I Properly Set the MySQL Root User Password on OS X?

Patricia Arquette
Patricia ArquetteOriginal
2024-12-20 16:21:11325browse

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!

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