在OS X環境下MySQL啓動時報錯

016-03-03T00:02:30.483037Z 0 [ERROR] InnoDB: Unable to lock ./ibdata1 error: 35
2016-03-03T00:02:30.483100Z 0 [Note] InnoDB: Check that you do not already have another mysqld process using the same InnoDB data or log files.

終端不斷地重複打印上面的錯誤日誌,從錯誤日誌看起來彷佛有另一個mysqld進程佔用了./ibdata1文件,因而使用ps命令查看是否有mysqld進程在運行:mysql

ps -ef |grep mysqld
74  7711     1   0  8:04上午 ??         0:00.34 /usr/local/mysql/bin/mysqld --user=_mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --log-error=/usr/local/mysql/data/mysqld.local.err --pid-file=/usr/local/mysql/data/mysqld.local.pid

發現有一個7711的進程在運行,因而強制kill掉:sql

sudo kill -9 7711

再次ps查詢:oracle

ps -ef |grep mysqld
74  7759     1   0  8:10上午 ??         0:00.29 /usr/local/mysql/bin/mysqld --user=_mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --log-error=/usr/local/mysql/data/mysqld.local.err --pid-file=/usr/local/mysql/data/mysqld.local.pid

發現還在,只不過pid由原來的7711變成了如今的7759,那麼看看mysqld進程打開了哪些文件:spa

lsof -c mysqld

該進程沒有打開任何文件,這就見鬼了。因而再次運行:日誌

sudo lsof -c mysqld
COMMAND  PID   USER   FD     TYPE             DEVICE  SIZE/OFF    NODE NAME
mysqld  8655 _mysql  cwd      DIR                1,4       544 3090250 /usr/local/mysql/data
mysqld  8655 _mysql  txt      REG                1,4  31130736 3089789 /usr/local/mysql/bin/mysqld

的確發現有一個實實在在的mysqld進程在運行,也佔用的這些mysql文件,通過一番Google大法,發如今OS X中啓動MySQL跟在Linux中啓動方式徹底是牛馬不相及,在OS X中啓動/重啓MySQL的正確姿式是:code

sudo launchctl unload -w /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist

此時再來看看是否還有mysqld進程:blog

ps -ef |grep mysqld

嗯,發現確實沒有了,再來啓動MySQL:進程

sudo launchctl load -w /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist
相關文章
相關標籤/搜索