Solve the problem that mac cannot log in when installing MySQL with homebrew

  • 2021-07-26 09:02:11
  • OfStack

If your computer is Mac, it is a very convenient way to install MySQL with homebrew, but there will still be some problems;

First, make sure you have installed mysql. If you installed it through homebrew, enter mysql.server start Startup service

If you enter


mysql -u root

This error ERROR 1045 (28000): Access denied for user 'zhongchengming' @ 'localhost' (using password: YES) should have failed to modify the initial password

Solution steps

(1) Terminal inputs mysqld_safe--skip-grant-tables are shown as follows

2017-03-21T11:44:11.6NZ mysqld_safe Logging to '/usr/local/var/mysql/zhongchengmingdeMacBook-Air.local.err'.
2017-03-21T11:44:11.6NZ mysqld_safe Logging to '/usr/local/var/mysql/zhongchengmingdeMacBook-Air.local.err'.
2017-03-21T11:44:11.6NZ mysqld_safe A mysqld process already exists

(2) Re-enter mysql-u root as shown below

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 5.7.17 Homebrew
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql >

(3) The terminal input use mysql is displayed as follows

Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql >

(4) Change the password UPDATE mysql.user SET authentication_string=PASSWORD('你的密码') WHERE User='root';

Successful Query OK, 1 row affected, 1 warning (0.05 sec)

Rows matched: 1 Changed: 1 Warnings: 1


Related articles: