Home > Database > Mysql Tutorial > Why Doesn't My New MySQL Root Password Work on macOS?

Why Doesn't My New MySQL Root Password Work on macOS?

Susan Sarandon
Release: 2024-12-07 08:57:19
Original
347 people have browsed it

Why Doesn't My New MySQL Root Password Work on macOS?

Troubleshooting MySQL Root User Password Setting on macOS

You may have followed the steps to set your MySQL root user password:

  1. Launch Terminal.
  2. Navigate to the MySQL binary folder: cd /usr/local/mysql/bin
  3. Execute: ./mysqladmin -u root password 'your_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:

  1. Connect to the MySQL terminal: mysql -u root
  2. Update the privilege tables:
mysql> USE mysql;
mysql> UPDATE user SET authentication_string=PASSWORD("your_password") WHERE User='root';
mysql> FLUSH PRIVILEGES;
mysql> quit
Copy after login

For MySQL Versions 8.0 and Up:

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

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!

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