MariaDB error failed to start, errno 12

time to read 2 min | 246 words

This server host about 4 blogs that all run with MariaDB 10. After a few days running, MariaDB service keep failing on this micro EC2 AWS with error like this.

120423 09:13:38 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
120423 09:14:27 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
120423  9:14:27 [Note] Plugin 'FEDERATED' is disabled.
120423  9:14:27 InnoDB: The InnoDB memory heap is disabled
120423  9:14:27 InnoDB: Mutexes and rw_locks use GCC atomic builtins
120423  9:14:27 InnoDB: Compressed tables use zlib 1.2.3
120423  9:14:27 InnoDB: Using Linux native AIO
120423  9:14:27 InnoDB: Initializing buffer pool, size = 512.0M
InnoDB: mmap(549453824 bytes) failed; errno 12
120423  9:14:27 InnoDB: Completed initialization of buffer pool
120423  9:14:27 InnoDB: Fatal error: cannot allocate memory for the buffer pool
120423  9:14:27 [ERROR] Plugin 'InnoDB' init function returned error.
120423  9:14:27 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
120423  9:14:27 [ERROR] Unknown/unsupported storage engine: InnoDB
120423  9:14:27 [ERROR] Aborting

Error 12 is OS error code:(ENOMEM) Out of memory, so of course you could just throw more memory to it. Or you could just enable swap to make MariaDB didn’t crash anymore. By default micro EC2 didn’t have a swap, so we should run a few linux command to make one.

sudo dd if=/dev/zero of=/swaps bs=1M count=1024
sudo mkswap /swaps
sudo swapon /swaps

Taadaa!! Your MariaDB instance should run flawlessly now. To make your change run for every reboot, Add this line /swaps swap swap defaults 0 0 to /etc/fstab.