Mac login MySQL error 1045


Mac login MySQL error 1045 (28000): access denied for user ‘root’ @ ‘localhost’ (using password: no)

Environmental Science

MySQL version: 5.7.12
Operating system: OSX 10.14.6 (18g84)
Installation file:. DMG download installation package (I selectedMacOS 10.14 (x86, 64 bit), DMG ArchiveVersion download of)

Mysql-5.7.26-mac OS 10.14-x86_.dmg

Step 1

Close the MySQL service. Whether you open MySQL service or not, you need to run the following commands to be on the safe side.

sudo /usr/local/mysql/support-files/mysql.server stop

(Note: I have reported an error here: error! MySQL server PID file could not be found! I can directly enter MySQL in the system preference settings (at the bottom) and close it. The second step is the same.)

Step 2

Start MySQL in safe mode.

sudo /usr/local/mysql/bin/mysqld_safe --skip-grant-tables

(the second step seems to be difficult, as follows:

1. Enter the command to add MySQL path in the terminal:


Note: as long as you find this kind of error reporting MySQL: command not found, you can use the path code, and then enter the command line of error reporting before you

2. Get administrator permission

Sudo Su (enter your notebook password)

3. Log in to MySQL directly over the permission table

​ mysqld_safe –skip-grant-tables –skip-networking &

In security mode, you can directly open MySQL command line window without password.

Step 3

Create a new terminal and change the root password

Note here that the password field in mysql.user table has been changed to: authentication [u string] compared with the previous version in 5.7

Enter the following commands one by one, change the root password and exit. If you continue to use password, an error will be reported. This field cannot be found. New password: 12345

mysql -u root
UPDATE mysql.user SET authentication_string=PASSWORD('12345') WHERE User='root';

take12345Change to your new password. After running the above command, the password of root will be changed to the password you set


Run the following command to test if the password was modified successfully.

mysql -u root -p

Then enter your new password.

If the input is correct, the MySQL command line window should appear, as follows:


Reference resources

[MySQL changes root password for Mac error: error 1045 (28000): access denied for user ‘root’ @ ‘localhost’ (using password: no)