本文也可以到我的网站“敲代码”去查看 http://www.qiaodm.com/article/235.shtml
今天突然发现程序日志报错Incorrect key file for table '/tmp/#sql_15cc_14.MYI'; try to repair it,Mysql数据库打不开了,网站也挂了,真心着急。查了好多资料,也没搞定,最后汇总各方方案总结出以下的解决办法:
1. 查看Mysql日志 /var/log/mysql/error.log 里面有下面的错误
130910 9:52:31 [ERROR] /mysql/mysql5.5.24/bin/mysqld: Incorrect key file for table '/tmp/#sql_15cc_14.MYI'; try to repair it
130910 9:52:31 [ERROR] Got an error from unknown thread, /pb2/build/sb_0-5519472-1334854211.98/mysql-5.5.24/storage/myisam/mi_write.c:223
2. 运行命令df -h查看磁盘空间,发现/tmp目录磁盘空间不足,/tmp目录是MYSQL的临时目录,可以在Mysql配置文件/etc/mysql/my.cnf中发现tmpdir = /tmp这一行。
root@AY140706210127235f2dZ:/var/log/mysql# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 20G 12G 6.8G 64% /
udev 2.0G 4.0K 2.0G 1% /dev
tmpfs 370M 268K 370M 1% /run
none 5.0M 0 5.0M 0% /run/lock
none 1.9G 0 1.9G 0% /run/shm
overflow 1M 1024K 0 100% /tmp
3. 上面命令发现/tmp目录没有磁盘空间了,那我就加一些磁盘空间,运行命令mount -t tmpfs -o size=100M none /tmp之后
root@AY140706210127235f2dZ:/var/log/mysql# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 20G 12G 6.8G 64% /
udev 2.0G 4.0K 2.0G 1% /dev
tmpfs 370M 268K 370M 1% /run
none 5.0M 0 5.0M 0% /run/lock
none 1.9G 0 1.9G 0% /run/shm
overflow 100M 176K 100M 1% /tmp
none 100M 176K 100M 1% /tmp
4. 重启MYSQL,运行命令 service mysqld restart 完美解决。
5. 如果还是起不来Mysql运行命令 /usr/bin/mysqld_safe & 也可以启动