因爲以前第一次裝MySQL,默認的datadir在啓動盤中,我想要將datadir移動到更大的存儲盤中。無奈網上的各類文章的方法在我這裏老是不work。我決定從新用homebrew來裝一遍MySQL。mysql
但是因爲以前各類嘗試致使的亂七八糟的操做過多,以致於我連以前裝MySQL的方法也用不了了。無奈之下,只得一步步摸索重來。sql
1. 完全清除MySQLspa
以前混亂操做過多,因而只得相對完全地把以前的痕跡清除code
ps -ax | grep mysql # stop and kill any MySQL processes # rm files and directories sudo rm /usr/local/mysql sudo rm -rf /usr/local/var/mysql sudo rm -rf /usr/local/mysql* sudo rm ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist sudo rm -rf /Library/StartupItems/MySQLCOM sudo rm -rf /Library/PreferencePanes/My* launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist # edit /etc/hostconfig and remove the line MYSQLCOM=-YES- # rm files and directories rm -rf ~/Library/PreferencePanes/My* sudo rm -rf /Library/Receipts/mysql* sudo rm -rf /Library/Receipts/MySQL* sudo rm -rf /private/var/db/receipts/*mysql* # try to run mysql, it shouldn't work
注意,除此以外, 還要將如下文件或文件夾好好查看及清理server
/tmp/ #這裏有mysql.sock 以及 mysql.sock.lock 文件,我以前不當心把lock文件的user改爲_mysql了,致使後面一直不work。所以,最好把這兩個文件都刪掉
/etc/my.cnf #這個文件當時建立之後就沒扔,致使後來重裝總出問題,也把這個文件刪掉
2. brew installblog
接下來,就能夠使用brew來安裝了進程
brew doctor # and fix any errors brew uninstall mysql brew cleanup brew update brew install mysql unset TMPDIR mysql_install_db --verbose --user=·whoami· --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql #5.7 沒有 --tmpdir選項 mysql.server start
接下來應該就沒有問題了。homebrew
若是還有問題,多是你以前已經成功登錄,可是忘了ip
lsof -i TCP:3306 # 找到正在佔用ip的process id kill [pid] # 終止該進程
mysql.server start
Referencerem
http://stackoverflow.com/questions/4359131/brew-install-mysql-on-mac-os
http://stackoverflow.com/questions/9918062/another-mysqld-server-running-on-port-3306-error