Homebrew(brew)安裝MySQL成功后無法登錄


Homebrew簡稱brew,OSX上的軟件包管理工具,在Mac終端可以通過brew安裝、更新、卸載各種軟件,(簡直就是神器級武器)。

廢話不多說,沒安裝brew自己去百度學習安裝,這里就不多說了。

1、首先在終端使用命令,這是搜索brew上的MySQL各個版本
brew search mysql
2、選擇自己需要的版本,安裝MySQL,這里我安裝為5.7版本
brew install mysql@5.7
3、執行后稍等片刻,它會自動安裝,以下為安裝成功后顯示的信息
MySQL is configured to only allow connections from localhost by default

To connect run:
    mysql -uroot

mysql@5.7 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.

If you need to have mysql@5.7 first in your PATH run:
  echo 'export PATH="/usr/local/opt/mysql@5.7/bin:$PATH"' >> ~/.bash_profile

For compilers to find mysql@5.7 you may need to set:
  export LDFLAGS="-L/usr/local/opt/mysql@5.7/lib"
  export CPPFLAGS="-I/usr/local/opt/mysql@5.7/include"


To have launchd start mysql@5.7 now and restart at login:
  brew services start mysql@5.7
Or, if you don't want/need a background service you can just run:
  /usr/local/opt/mysql@5.7/bin/mysql.server start
==> Summary
🍺  /usr/local/Cellar/mysql@5.7/5.7.23: 317 files, 234.1MB

以上信息需注意系統環境變量的配置:

echo 'export PATH="/usr/local/opt/mysql@5.7/bin:$PATH"' >> ~/.bash_profile

# 文件修改以后執行寫入bash_profile以后執行立即生效
sousers ~/.bash_profile
4、最后執行,啟動MySQL
mysql.server start

# 顯示如下,則安裝成功
Starting MySQL
. SUCCESS! 

附加:

終端輸入

mysql -u root

如果你運氣不好,出現如下錯誤,應該是修改初始密碼沒有成功

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES),
解決步驟

(1)終端輸入 mysqld_safe --skip-grant-tables 顯示如下

mysqld_safe --skip-grant-tables

# 顯示如下
2017-03-21T11:44:11.6NZ mysqld_safe Logging to '/usr/local/var/mysql/huang.local.err'.
2017-03-21T11:44:11.6NZ mysqld_safe Logging to '/usr/local/var/mysql/huang.local.err'.
2017-03-21T11:44:11.6NZ mysqld_safe A mysqld process already exists

(2)再次輸入 mysql -u root 顯示如下

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)終端輸入 use mysql顯示如下

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)修改密碼 UPDATE mysql.user SET authentication_string=PASSWORD('你的密碼') WHERE User='root';

成功  Query OK, 1 row affected, 1 warning (0.05 sec)
Rows matched: 1  Changed: 1  Warnings: 1

到這來就完成啦。
最后重新登終端輸入:
mysql -u root -p
按回車鍵,輸入設置的密碼即可登錄

以上所述給大家介紹的解決mac使用homebrew安裝MySQL,並出現無法登陸問題的解決方案,希望對大家有所幫助。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM