操作系统版本:Ubuntu 13.04
mysql 版本:mysql-server-5.5
现象:突然之前接到报告说数据库启不来了。第一时间查看硬盘空间,看是否硬盘满了。发现空间使用正常。
root@ns-xxzx-svr:~# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 19G 16G .3G % /
none .0K .0K % /sys/fs/cgroup
udev 494M .0K 494M % /dev
tmpfs 101M 820K 100M % /run
none 5.0M 5.0M % /run/lock
none 502M 72K 502M % /run/shm
none 100M 276K 100M % /run/user
/dev/sdb1 197G 59G 129G % /hos_media
/dev/sdc1 197G 42G 146G % /root/sdc1
然后查看mysql的出错日志。
root@ns-xxzx-svr:/var/log/mysql# cat error.log
:: [Warning] Using unique option prefix myisam-recover instead of myisam-recover-options is deprecated and will be removed in a future release. Please use the full name instead.
:: [Note] Plugin 'FEDERATED' is disabled.
:: InnoDB: The InnoDB memory heap is disabled
:: InnoDB: Mutexes and rw_locks use GCC atomic builtins
:: InnoDB: Compressed tables use zlib 1.2.
:: InnoDB: Using Linux native AIO
:: InnoDB: Initializing buffer pool, size = 128.0M
InnoDB: mmap( bytes) failed; errno
:: InnoDB: Completed initialization of buffer pool
:: InnoDB: Fatal error: cannot allocate memory for the buffer pool
:: [ERROR] Plugin 'InnoDB' init function returned error.
:: [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
:: [ERROR] Unknown/unsupported storage engine: InnoDB
:: [ERROR] Aborting :: [Note] /usr/sbin/mysqld: Shutdown complete
从报错上查看有点像 InnoDB的数据引擎的问题,顺着这个方向会越走越远。通过关键字搜索也都是搜的无关的内容。一时没有头绪。
将报错信息一条条的在google里搜索。当以”InnoDB: mmap(135987200 bytes) failed“为关键字搜索时出现一条有用信息。
会不会也是因为内存过低?这台服务器内存只有1G,有可能造成mysql服务启动不了或宕机。
root@ns-xxzx-svr:/var/log/mysql# free -m
total used free shared buffers cached
Mem:
-/+ buffers/cache:
Swap:
有人建议多加点swap空间。
我查了下服务器中swap空间使用情况:
root@ns-xxzx-svr:/var/log/mysql# sudo swapon -s
Filename Type Size Used Priority
/dev/sda5 partition -
果真,swap分区已用完。这可能就是导致mysql崩溃的原因。内存不够,虚拟内存也不够。不崩才怪。
果断加swap空间。
root@ns-xxzx-svr:/var/log/mysql# parted /dev/sdd
(parted) print
Model: HUAWEI XSG1 (scsi)
Disk /dev/sdd: 1100GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt Number Start End Size File system Name Flags (parted) mkpart primary 4G
(parted) print
Model: HUAWEI XSG1 (scsi)
Disk /dev/sdd: 1100GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt Number Start End Size File system Name Flags
1024MB 4000MB 2976MB primary (parted) mkpart primary 4G 500G
(parted) mkpart primary 500G -
(parted) print
Model: HUAWEI XSG1 (scsi)
Disk /dev/sdd: 1100GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt Number Start End Size File system Name Flags
1024MB 4000MB 2976MB primary
4000MB 500GB 496GB primary
500GB 1100GB 600GB primary (parted) quit
root@ns-xxzx-svr:/var/log/mysql# mkswap /dev/sdd1
Setting up swapspace version , size = KiB
no label, UUID=-bcda-471f-8a17-7d4f150752d6
root@ns-xxzx-svr:/var/log/mysql# sudo swapon /dev/sdd1
root@ns-xxzx-svr:/var/log/mysql# sudo swapon -s
Filename Type Size Used Priority
/dev/sda5 partition -
/dev/sdd1 partition -
加好了之后,查看swap分区使用情况,还有剩余。下面开始尝试启动mysql服务,看能否启动。
root@ns-xxzx-svr:/var/log/mysql# /etc/init.d/mysql start
Rather than invoking init scripts through /etc/init.d, use the service()
utility, e.g. service mysql start Since the script you are attempting to invoke has been converted to an
Upstart job, you may also use the start() utility, e.g. start mysql
mysql start/running, process
终于活过来了。
参考: