1. 程式人生 > >Homebrew(brew)安裝MySQL成功後無法登入

Homebrew(brew)安裝MySQL成功後無法登入

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

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

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

To connect run:
    mysql -uroot

[email protected]
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 [email protected] first in your PATH run: echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.bash_profile For compilers to find
[email protected]
you may need to set: export LDFLAGS="-L/usr/local/opt/[email protected]/lib" export CPPFLAGS="-I/usr/local/opt/[email protected]/include" To have launchd start [email protected] now and restart at login: brew services start [email protected] Or, if you don't want/need a background service you can just run: /usr/local/opt/
[email protected]
/bin/mysql.server start ==> Summary ? /usr/local/Cellar/[email protected]/5.7.23: 317 files, 234.1MB

以上資訊需注意系統環境變數的配置:

echo 'export PATH="/usr/local/opt/[email protected]/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,並出現無法登陸問題的解決方案,希望對大家有所幫助。