about 3 years ago


Mac OS X Yosemite 10.10.2


MySQL 5.5.40


1. 安裝 Mac 套件管理 - Homebrew

如果系統還沒安裝 Homebrew,可以依照下面指令安裝。

$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
$ brew doctor
$ brew update

2. 使用 Homebrew 安裝 git 版本控制

透過 Homebrew 可以輕鬆安裝想要的套件,例如 git

$ brew install -v git

3. 安裝 Command Lind Developer Tools


$ xcode-select --install

4. 安裝 MySQL 5.5

4.1 移除其他版本

如果已經安裝 5.6 版本請依下面方式移除

$ launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
$ rm ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
$ brew uninstall mysql

4.2 安裝 5.5.40 版本

$ brew install mysql55

4.3 MySQL 設定檔

在安裝好之後,我們要複製一份 MySQL 的設定檔,這時候可以前往 MySQL 目錄 $(brew --prefix mysql55)/support-files/,主要可以看到 4 個檔案如下:

  • my-huge.cnf:適合 1G~2G RAM 的主機
  • my-large.cnf:適合 512MB RAM 的主機
  • my-medium.cnf:適合 32MB~64MB RAM的主機
  • my-small.cnf:適合少於 64MB RAM的主機

可以考量自己主機後複製適合的 cnf 檔案

$ cp -v $(brew --prefix mysql55)/support-files/my-huge.cnf $(brew --prefix mysql55)/my.cnf

4.4 開機自動啟用

Symbol link MySQL 本身的 plist 至使用者 ~/Library/LaunchAgents 資料夾後載入開機啟動

$ ln -sfv /usr/local/opt/mysql55/*.plist ~/Library/LaunchAgents
$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql55.plist

4.5 設置 root 密碼

在預設上, MySQL 的 root 使用者帳號是沒有密碼的,你可以使用以下指令來設置想要的密碼。

將 MySQL 的 bin 資料夾路徑添加至 .zshrc 檔案中,完成之後重啟終端機。

export PATH=$(brew --prefix mysql55)/bin:$PATH


$ mysql_secure_installation


In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!

By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] Y
 ... Success!

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y

Cleaning up...

All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!


← 讓 Mac 終端機更強大、更美化 Rails 4 實作 TinyMCE 編輯器 →
comments powered by Disqus