mac安裝mysql


參考鏈接

  1. 基本安裝指導
  2. 修復安裝指定版本的問題

安裝說明

安裝詳情都是根據上述參考鏈接進行總結的。

安裝命令

安裝最新版本

brew install mysql

安裝指定版本,比如5.7

brew install mysql@5.7

安裝結果

安裝的基本詳情都會在返回結果里面體現,所以小白可以加強對返回結果的理解。

brew install mysql@5.7
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> Updated Formulae
fs-uae
==> Downloading https://homebrew.bintray.com/bottles/mysql@5.7-5.7.26.mojave.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/81/815ae8aa8c765f57e806ff9197eaa5783b138c493d68333c553b25f441b6af3e?__gda__=exp=1562923064~hmac=31bc462198d92c1629a8360acc4514c48c
######################################################################## 100.0%
==> Pouring mysql@5.7-5.7.26.mojave.bottle.tar.gz
==> /usr/local/Cellar/mysql@5.7/5.7.26/bin/mysqld --initialize-insecure --user=songzeyu --basedir=/usr/local/Cellar/mysql@5.7/5.7.26 --datadir=/usr/local/var/mysql --tmpdir=/tmp
==> Caveats
We've installed your MySQL database without a root password. To secure it run:
    mysql_secure_installation
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.26: 320 files, 231.8MB

對上面命令進行提取

mysql連接

mysql -uroot

導入執行命令

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

啟動mysql服務

brew services start mysql@5.7
/usr/local/opt/mysql@5.7/bin/mysql.server start

如果默認安裝了最新版本,需要降級,那么請參考

修復安裝指定版本的問題

密碼設置(暫未驗證)

安裝好之后,mysql 的 root 用戶默認是空密碼,首先設置密碼:

mysql_secure_installation

​ 因為 mysql5.7 增加了密碼驗證,所以在執行上一步后,你會看到這條信息:

 Would you like to setup VALIDATE PASSWORD plugin?

意思就是是否安裝密碼驗證插件,個人建議不安裝,因為安裝之后你只能設置一個非常復雜的密碼,麻煩的很。所以此時要輸入no,不安裝。如果你已經選擇了y,不要緊,你可以連接 mysql 終端之后,執行命令卸載該插件:

UNINSTALL PLUGIN validate_password;

卸載成功!現在再執行一次mysql_secure_installation,選擇不加載密碼驗證插件,你就可以設置一個簡單的密碼啦!

連接mysql

安裝上述命令安裝成功后,驗證是否成功:

mysql -u root 

!!!出現了意料之外的情況!!!

-bash: mysql: command not found

嚇到了,接連試了好幾次,還是同樣的問題。

根據上述參考資料進行修復,解決方案如下:

brew link mysql@5.7 --force

執行上述命令后,回顯如下:

> Linking /usr/local/Cellar/mysql@5.7/5.7.23... 87 symlinks created

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

意思就是讓你執行下面命令

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

再次執行連接命令

mysql -u root 

連接成功

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 43
Server version: 5.7.26 Homebrew

Copyright (c) 2000, 2019, 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>

啟動mysql的命令:

mysql.server start
brew services start mysql@5.7


免責聲明!

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



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