slan's blog

Face loneliness, or seek comfort in temporary escapes?

mysql无法启动排错

2013-04-28 11:53:00 +0000 UTC

mysql无法启动排错

上班打开虚拟机,系统是ubuntu,在连接数据库的时候发现无法连接数据库

试着启动mysql:执行service mysql start 提示:Job failed to start

在终端执行mysql命令:提示:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

继续找日志,发现/var/log下的mysql都没有日志。。

只有系统日志,打开syslog这个文件,发现:

Apr 28 10:54:22 localhost kernel: [   31.015430] init: mysql main process (901) terminated with status 1

Apr 28 10:54:22 localhost kernel: [   31.015457] init: mysql main process ended, respawning

Apr 28 10:54:23 localhost kernel: [   31.930266] init: mysql post-start process (902) terminated with status 1

Apr 28 10:54:23 localhost kernel: [   31.939001] type=1400 audit(1367117663.768:12): apparmor="STATUS" operation="profile_replace" name="/usr/sbin/mysqld" pid=949 comm="apparmor_parser"

Apr 28 10:54:24 localhost kernel: [   33.060400] init: mysql main process (953) terminated with status 1

Apr 28 10:54:24 localhost kernel: [   33.060426] init: mysql respawning too fast, stopped

只提示mysql进程无法启动。还是没办法定位问题。

在修改了几个配置,仍然无法启动之后,决定重装mysql。。

先备份数据库文件,防止数据跟表都没了。cd到/var/lib/mysql/ 这个目录下,将整个目录拷走。然后重装mysql。

悲剧的是,重装之后依然无法启动。万幸的是mysql错误日志出来了,位置在\var\log\mysql\error.log

发现以下error:

130428 11:28:55 [ERROR] /usr/sbin/mysqld: Table './mysql/db' is marked as crashed and last (automatic?) repair failed

130428 11:28:55 [ERROR] Fatal error: Can't open and lock privilege tables: Table './mysql/db' is marked as crashed and last (automatic?) repair failed

130428 11:28:55 [ERROR] /usr/sbin/mysqld: File '/var/run/mysqld/mysqld.pid' not found (Errcode: 13)

130428 11:28:55 [ERROR] /usr/sbin/mysqld: Error reading file 'UNKNOWN' (Errcode: 9)

130428 11:28:55 [ERROR] /usr/sbin/mysqld: Error on close of 'UNKNOWN' (Errcode: 9)

发现是mysql库下db这个表有问题,导致启动失败,cd 到存表文件的目录/var/lib/mysql/mysql 然后执行修复文件命令:myisamchk -of db.MYI 重新启动。终于启动成功了。

还有怎么找存放mysql数据文件的路径,可以执行 find / -name *.MYD