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
Release: 2024-12-20 16:21:11
Original
324 people have browsed it

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
Copy after login

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
Copy after login

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';
    Copy after login
  • MySQL 8.0 and above: Use the ALTER USER command instead to set the password.

    mysql> `ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';` 
    Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template