MySQL启动报错问题InnoDB:Unable to lock/ibdata1 error
在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进程在运行:
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掉:
sudo kill -9 7711
再次ps查询:
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进程打开了哪些文件:
lsof -c mysqld
该进程没有打开任何文件,这就见鬼了。
mac os x, lsof only shows your own processes unless running as root with sudo
于是再次运行:
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的正确姿势是:
sudo launchctl unload -w /library/launchdaemons/com.oracle.oss.mysql.mysqld.plist
此时再来看看是否还有mysqld进程:
ps -ef |grep mysqld
嗯,发现确实没有了,再来启动mysql:
sudo launchctl load -w /library/launchdaemons/com.oracle.oss.mysql.mysqld.plist
问题总算解决,但还没完,总得把原理搞清楚才行。
launchd是什么?
launchd是mac os x从10.4开始引入,用于用于初始化系统环境的关键进程,它是内核装载成功之后在os环境下启动的第一个进程。传统的linux会使用/etc/rc.*或者/etc/init来管理开机要启动的服务,而在os x中就是使用launchd来管理。采用这种方式来配置启动项很简单,只需要一个plist文件。/library/launchdaemons目录下的plist文件都是系统启动后立即启动进程。使用launchctl命令加载/卸载plist文件,加载配置文件后,程序启动,卸载配置文件后程序关闭。
卸载配置文件后又尝试直接用mysqld命令来启动mysql进程试试:
/usr/local/mysql/bin/mysqld 2016-03-03t01:35:50.359258z 0 [error] innodb: ./ib_logfile0 can't be opened in read-write mode. 2016-03-03t01:35:50.359283z 0 [error] innodb: plugin initialization aborted with error generic error 2016-03-03t01:35:50.670517z 0 [error] plugin 'innodb' init function returned error. 2016-03-03t01:35:50.670555z 0 [error] plugin 'innodb' registration as a storage engine failed. 2016-03-03t01:35:50.670568z 0 [error] failed to initialize plugins. 2016-03-03t01:35:50.670574z 0 [error] aborting
ib_logfile0不能被打开,猜测是用户权限文件,不能用当前系统用户启动mysql。那么加上sudo看看,用root来启动:
2016-03-03t01:38:10.977313z 0 [error] fatal error: please read "security" section of the manual to find out how to run mysqld as root! 2016-03-03t01:38:10.977339z 0 [error] aborting 2016-03-03t01:38:10.977350z 0 [note] binlog end 2016-03-03t01:38:10.977410z 0 [note] /usr/local/mysql/bin/mysqld: shutdown complete
叫我去读mysql的安全手册,还是用launchd的方式启动吧。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
上一篇: js实现单元格拖拽效果
下一篇: MySQL触发器概念、原理与用法详解
推荐阅读
-
MySQL启动报错问题InnoDB:Unable to lock/ibdata1 error
-
Mysql启动中 InnoDB: Error: log file ./ib_logfile0 is of different size 0 5242880 bytes 的问题
-
启动mysql时报错:ERROR! MySQL is not running, but lock file (/var/lock/subsys/mysql) exists的解决办法
-
Mysql启动中 InnoDB: Error: log file ./ib_logfile0 is of different size 0 5242880 bytes 的问题
-
MySQL启动报错问题InnoDB:Unable to lock/ibdata1 error
-
启动mysql时报错:ERROR! MySQL is not running, but lock file (/var/lock/subsys/mysql) exists的解决办法