mysql启动失败一例

操作系统版本: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  2.3G  88% /
none            4.0K     0  4.0K   0% /sys/fs/cgroup
udev            494M  4.0K  494M   1% /dev
tmpfs           101M  820K  100M   1% /run
none            5.0M     0  5.0M   0% /run/lock
none            502M   72K  502M   1% /run/shm
none            100M  276K  100M   1% /run/user
/dev/sdb1       197G   59G  129G  32% /hos_media
/dev/sdc1       197G   42G  146G  23% /root/sdc1

然后查看mysql的出错日志。

root@ns-xxzx-svr:/var/log/mysql# cat error.log
181109  9:10:09 [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.
181109  9:10:09 [Note] Plugin 'FEDERATED' is disabled.
181109  9:10:09 InnoDB: The InnoDB memory heap is disabled
181109  9:10:09 InnoDB: Mutexes and rw_locks use GCC atomic builtins
181109  9:10:09 InnoDB: Compressed tables use zlib 1.2.7
181109  9:10:09 InnoDB: Using Linux native AIO
181109  9:10:09 InnoDB: Initializing buffer pool, size = 128.0M
InnoDB: mmap(135987200 bytes) failed; errno 12
181109  9:10:09 InnoDB: Completed initialization of buffer pool
181109  9:10:09 InnoDB: Fatal error: cannot allocate memory for the buffer pool
181109  9:10:09 [ERROR] Plugin 'InnoDB' init function returned error.
181109  9:10:09 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
181109  9:10:09 [ERROR] Unknown/unsupported storage engine: InnoDB
181109  9:10:09 [ERROR] Aborting

181109  9:10:09 [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:          1002        930         72          0          1          8
-/+ buffers/cache:        919         82
Swap:         1021       1021          0

有人建议多加点swap空间。

我查了下服务器中swap空间使用情况:

root@ns-xxzx-svr:/var/log/mysql# sudo swapon -s
Filename                                Type            Size    Used    Priority
/dev/sda5                               partition       1046524 1046524 -1

果真,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 1024 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
 1      1024MB  4000MB  2976MB               primary

(parted) mkpart primary 4G 500G
(parted) mkpart primary 500G -1
(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
 1      1024MB  4000MB  2976MB               primary
 2      4000MB  500GB   496GB                primary
 3      500GB   1100GB  600GB                primary

(parted) quit
root@ns-xxzx-svr:/var/log/mysql# mkswap /dev/sdd1
Setting up swapspace version 1, size = 2906108 KiB
no label, UUID=10628693-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       1046524 1046524 -1
/dev/sdd1                               partition       2906108 102636  -2

加好了之后,查看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(8)
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(8) utility, e.g. start mysql
mysql start/running, process 11805

终于活过来了。

参考:

【1】MySQL InnoDB: mmap(137363456 bytes) failed; errno 12

【2】Issue with mysql

【3】How To Add Swap on Ubuntu 12.04

 

posted on 2018-11-09 15:34  Digital_life  阅读(356)  评论(0编辑  收藏  举报

导航