Homebrew(brew)安裝MySQL成功後沒法登陸

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

廢話很少說,沒安裝brew本身去百度學習安裝,這裏就很少說了。sql

一、首先在終端使用命令,這是搜索brew上的MySQL各個版本
brew search mysql
二、選擇本身須要的版本,安裝MySQL,這裏我安裝爲5.7版本
brew install mysql@5.7
三、執行後稍等片刻,它會自動安裝,如下爲安裝成功後顯示的信息
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

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

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

# 文件修改之後執行寫入bash_profile之後執行當即生效
sousers ~/.bash_profile
四、最後執行,啓動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 顯示以下ui

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 顯示以下this

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顯示以下rest

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';code

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

到這來就完成啦。
最後從新登終端輸入:
mysql -u root -p
按回車鍵,輸入設置的密碼便可登陸orm

以上所述給你們介紹的解決mac使用homebrew安裝MySQL,並出現沒法登錄問題的解決方案,但願對你們有所幫助。

相關文章
相關標籤/搜索