Mysql login failure problem in mac environment Access denied for user 'root'@'localhost' (using password: YES)

Database connection problem


In the mac environment, various software always have inexplicable problems. Mysql encountered a problem today. It was very confusing. It was obviously the correct password but I couldn't log in. It was very uncomfortable. Later, an old man said that it was because the system believed that MySQL considered the random password provided during installation unsafe and asked the user to reset the password. Of course, I don’t know what’s going on, and I think it’s possible that my password is wrong. Wrong, then change the password. I will record my operation process for your reference.

Step one: close mysql


Apple -> System Preferences -> Click MySQL at the bottom and turn off the mysql service

Step 2: Enter terminal settings


1. Enter the terminal and type (cd /usr/local/mysql/bin/) and press Enter

cd /usr/local/mysql/bin/

2. Enter (sudo su) and press Enter to obtain administrator rights.

sudo su

You should note here that when you enter sudo su, you need to enter the administrator password of your own computer (the password that allows you to install software)

3. Enter (./mysqld_safe --skip-grant-tables &) and press Enter to disable the mysql verification function. Mysql will automatically restart and the mysql status in the preferences will change to running.

./mysqld_safe --skip-grant-tables &

4. Enter the command (./mysql) and press Enter.
5. Enter the command (flush privileges;). Don’t forget to enter the semicolon.
6. Reset password: ALTER USER 'root'@'localhost' IDENTIFIED BY 'your new password';
7. Execute quit; exit mysql.
8. Execute exit; exit sudo.
9. The password reset has been completed. You can try to log in to mysql.

Guess you like

Origin blog.csdn.net/qq_27981847/article/details/132759414