標籤:
用brew安裝mysql
brew install mysql
開機啟動
ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgentslaunchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
2.查看設定檔引用的路徑
mysqld --help --verbose | more
通過這命令,可以看出mysql預設調用的設定檔路徑:
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/local/etc/my.cnf ~/.my.cnf
然後,我們搜尋一下目錄下的檔案是否已經建立:
cd /find . -name "my.cnf"
3. 建立設定檔
通常這幾個路徑都是沒有建立設定檔的,我們自己建立一下。
先找出我們安裝的mysql的配置範例檔案,在安裝檔案中的support-files檔案夾中:
ls $(brew --prefix mysql)/support-files/my-*
複製到引用目錄:
cp /usr/local/opt/mysql/support-files/my-default.cnf /etc/my.cnf
然後就可以按自己需求修改配置了
4.重新mysql, unload 是關閉, load是啟動
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plistlaunchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
為了檔案管理可以把命令alias下:
vim ~/.bash_aliases
輸入以下內容,儲存
alias mysql.start="launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist"
alias mysql.stop="launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist"
alias mysql.restart=‘mysql.stop && mysql.start‘
儲存後
echo "[[ -f ~/.bash_aliases ]] && . ~/.bash_aliases" >> ~/.bash_profile source ~/.bash_profile
這樣,直接調用命令
mysql.start
mysql.stop
mysql.restart
就可以控制開啟,關閉和重啟了
修改用brew安裝的mysql配置