查看: 1966|回復: 0

[Mysql數據庫] os x 10.10.5下用brew安裝mysql

3萬

主題

3萬

帖子

10萬

積分

管理員

Rank: 9Rank: 9Rank: 9

積分
100197
發表于 2015-12-2 18:44:47

os x 10.10.5下用brew安裝mysql,有需要的朋友可以參考下。


homebrew是mac下一個很好的包管理器,通過它安裝一些軟件很方便,而且便于管理。雖然MySQL官方提供了mac的安裝包,但我還是習慣于用brew安裝mysql。

Taps

因為brew是從github下載的軟件包,所以可能會很慢,我這里是用的ss+proxychains-ng強制brew使用socks5代理的。關于proxychains-ng的具體用法我這里最不贅述了。

準備工作

首先brew serach mysql,搜索到很多mysql相關的包:

  1. automysqlbackup mysql mysql-sandbox
  2. groonga-normalizer-mysql mysql++ mysql-search-replace
  3. homebrew/versions/mysql51 mysql-cluster mysqltuner
  4. homebrew/versions/mysql55 mysql-connector-c
  5. homebrew/versions/mysql56 mysql-connector-c++
  6. homebrew/php/php53-mysqlnd_ms homebrew/php/php56-mysqlnd_ms
  7. homebrew/php/php54-mysqlnd_ms Caskroom/cask/mysqlworkbench
  8. homebrew/php/php55-mysqlnd_ms Caskroom/cask/navicat-for-mysql
復制代碼

因為我需要做C語言連接mysql,所以只需要安裝mysql。

安裝mysql

直接執行brew install mysql,如果需要使用proxychains-ng,就用proxychains4 brew install mysql,接下來就等mysql安裝好了,可是事情并沒有那么順利。

安裝過程中提示錯誤:

  1. Error: The 'brew link' step did not complete successfully
  2. The formula built, but is not symlinked into /usr/local
  3. Could not symlink share/man/man8/mysqld.8
  4. /usr/local/share/man/man8 is not writable.
  5. You can try again using:
  6. brew link mysql
復制代碼

當我使用brew link mysql建立mysql軟連接的時候出現同樣的錯誤。看錯誤的提示大概就是/usr/local/share/man/man8 is not writable這個目錄不可寫,這樣的話就簡單了。

執行brew doctor發現

  1. Warning: Some directories in /usr/local/share/man aren't writable.
  2. This can happen if you "sudo make install" software that isn't managed
  3. by Homebrew. If a brew tries to add locale information to one of these
  4. directories, then the install will fail during the link step.
  5. You should probably `sudo chown -R $(whoami)` them:
  6. /usr/local/share/man/man8
復制代碼

接著執行sudo chown -R $(whoami) /usr/local/share/man/man8,完美解決問題。

再brew link mysql成功,mysql相關的各種命令都已經鏈接到了/usr/local/bin目錄下。

需要注意的是,brew最后輸出的一段話:

  1. We've installed your MySQL database without a root password. To secure it run:
  2. mysql_secure_installation
  3. To connect run:
  4. mysql -uroot
  5. To have launchd start mysql at login:
  6. ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
  7. Then to load mysql now:
  8. launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
  9. Or, if you don't want/need launchctl, you can just run:
  10. mysql.server start
復制代碼
安全設置向導

需要注意的是,安裝好得mysql是沒有root密碼的,需要自己設置root密碼。

首先啟動mysql,mysql.server start,然后設置數據庫訪問權限,
mysql_secure_installation

  1. Securing the MySQL server deployment.
  2. Connecting to MySQL using a blank password.
  3. VALIDATE PASSWORD PLUGIN can be used to test passwords
  4. and improve security. It checks the strength of password
  5. and allows the users to set only those passwords which are
  6. secure enough. Would you like to setup VALIDATE PASSWORD plugin?
  7. Press y|Y for Yes, any other key for No: y <-是否使用VALIDATE PASSWORD PLUGIN,這個看自己了
  8. There are three levels of password validation policy:
  9. LOW Length >= 8
  10. MEDIUM Length >= 8, numeric, mixed case, and special characters
  11. STRONG Length >= 8, numeric, mixed case, special characters and dictionary file
  12. Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1(這里我選了1,即MEDIUM,密碼需要有大小寫字母、數字、特殊符號)
  13. Please set the password for root here.
  14. New password: (輸入你的密碼)
  15. Re-enter new password: (再次輸入你的密碼)
  16. Estimated strength of the password: 100
  17. Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
  18. By default, a MySQL installation has an anonymous user,
  19. allowing anyone to log into MySQL without having to have
  20. a user account created for them. This is intended only for
  21. testing, and to make the installation go a bit smoother.
  22. You should remove them before moving into a production
  23. environment.
  24. Remove anonymous users? (Press y|Y for Yes, any other key for No) : y(是否刪除匿名用戶,生產環境建議刪除)
  25. Success.
  26. Normally, root should only be allowed to connect from
  27. 'localhost'. This ensures that someone cannot guess at
  28. the root password from the network.
  29. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : (是否禁止root遠程登錄,根據自己的需求選擇Y/n并回車,建議禁止)
  30. ... skipping.
  31. By default, MySQL comes with a database named 'test' that
  32. anyone can access. This is also intended only for testing,
  33. and should be removed before moving into a production
  34. environment.
  35. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : (是否刪除test數據庫,直接回車)
  36. ... skipping.
  37. Reloading the privilege tables will ensure that all changes
  38. made so far will take effect immediately.
  39. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : (是否重新加載權限表,直接回車)
  40. ... skipping.
  41. All done! ```
復制代碼

如果想設置mysql開機啟動:
To have launchd start mysql at login:
ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
Then to load mysql now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
如果想自己手動啟動
Or, if you don’t want/need launchctl, you can just run:
mysql.server start



回復

使用道具 舉報