Mysql – InnoDB (Not Really) Out Of Memory

innodbmemoryMySQL

MySQL keeps on crashing on my server. I'm running several dozen sites using VestaCP and haven't had issues with MySQL for months.

I'm running on a Linode VPS with 12GB of Ram, normally 9GB of it being free.

The MySQL error log looks like this:

160711 22:32:36 [Note] Plugin 'FEDERATED' is disabled.
160711 22:32:36 InnoDB: The InnoDB memory heap is disabled
160711 22:32:36 InnoDB: Mutexes and rw_locks use GCC atomic builtins
160711 22:32:36 InnoDB: Compressed tables use zlib 1.2.8
160711 22:32:36 InnoDB: Using Linux native AIO
160711 22:32:39 InnoDB: Initializing buffer pool, size = 1.0G
InnoDB: mmap(1098907648 bytes) failed; errno 12
160711 22:32:39 InnoDB: Completed initialization of buffer pool
160711 22:32:39 InnoDB: Fatal error: cannot allocate memory for the buffer pool
160711 22:32:39 [ERROR] Plugin 'InnoDB' init function returned error.
160711 22:32:39 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
160711 22:32:39 [ERROR] Unknown/unsupported storage engine: InnoDB
160711 22:32:39 [ERROR] Aborting

160711 22:32:39 [Note] /usr/sbin/mysqld: Shutdown complete

160711 22:33:43 [Note] Plugin 'FEDERATED' is disabled.
160711 22:33:43 InnoDB: The InnoDB memory heap is disabled
160711 22:33:43 InnoDB: Mutexes and rw_locks use GCC atomic builtins
160711 22:33:43 InnoDB: Compressed tables use zlib 1.2.8
160711 22:33:43 InnoDB: Using Linux native AIO
160711 22:33:43 InnoDB: Initializing buffer pool, size = 1.0G
160711 22:33:43 InnoDB: Completed initialization of buffer pool
160711 22:33:43 InnoDB: highest supported file format is Barracuda.

This particular sets of errors seem to happen after issuing a service mysql restart command.

I spent a good deal of time looking at this particular error: Fatal error: cannot allocate memory for the buffer pool. Everything I found pointed at lack of ram being the issue, a majority of folks having this were on extremely low memory systems (512MB or so usually). Obviously, at 12GB of ram and 9GB free there shouldn't be an issue with not enough ram so I'm not sure what to do in this case.

Running free -h yields these results:

Command line results of free -h
Also, there are a TON of entries in the log files that look like this:

160711 22:31:58 [Warning] Aborted connection 5131 to db: 'xxxx' user: 'xxxx' host: 'localhost' (Got timeout reading communication packets)
160711 22:31:58 [Warning] Aborted connection 5127 to db: 'xxxx' user: 'xxxx' host: 'localhost' (Got timeout reading communication packets)
160711 22:32:00 [Warning] Aborted connection 5136 to db: 'xxxx' user: 'xxxx' host: 'localhost' (Got timeout reading communication packets)
160711 22:32:01 [Warning] Aborted connection 5134 to db: 'xxxx' user: 'xxxx' host: 'localhost' (Got timeout reading communication packets)
160711 22:32:01 [Warning] Aborted connection 5133 to db: 'xxxx' user: 'xxxx' host: 'localhost' (Got timeout reading communication packets)
160711 22:32:01 [Warning] Aborted connection 5112 to db: 'xxxx' user: 'xxxx' host: 'localhost' (Got timeout reading communication packets)
160711 22:32:01 [Warning] Aborted connection 5135 to db: 'xxxx' user: 'xxxx' host: 'localhost' (Got timeout reading communication packets)
160711 22:32:04 [Warning] Aborted connection 5137 to db: 'xxxx' user: 'xxxx' host: 'localhost' (Got timeout reading communication packets)
160711 22:32:05 [Warning] Aborted connection 5140 to db: 'xxxx' user: 'xxxx' host: 'localhost' (Got timeout reading communication packets)

Finally, I did try increasing the size of the InnoDB Buffer Pool from 512MB to 1GB and that hasn't seemed to help. Do I just crank up the buffer pool size until it stops crashing?

Edit: Thanks for the responses so far! Here is my current my.cnf:

[client]
port=3306
socket=/var/run/mysqld/mysqld.sock

[mysqld_safe]
socket=/var/run/mysqld/mysqld.sock

[mysqld]
user=mysql
pid-file=/var/run/mysqld/mysqld.pid
socket=/var/run/mysqld/mysqld.sock
port=3306
basedir=/usr
datadir=/var/lib/mysql
log-warning=2
tmpdir=/tmp
lc-messages-dir=/usr/share/mysql
log_error=/var/log/mysql/error.log
#skip-networking

symbolic-links=0

skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 256M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M

#innodb_use_native_aio = 0
innodb_file_per_table

max_connections=1500
max_user_connections=200
wait_timeout=10
interactive_timeout=50
long_query_time=5

innodb_log_buffer_size          = 32M
innodb_buffer_pool_size         = 1024M
innodb_log_file_size            = 768M

!includedir /etc/mysql/conf.d/

Best Answer

Your innodb buffer pool is too small. You need to increase it and like 4 other innodb parameters. Basically, you tell the innodb engine in the mysql config how much ram it gets. Presumably this is to keep horrible things from happening to your data if the machine runs out of ram.

If you have a lot of innodb tables make the buffer pool really really large, like ideally it can be the size of all your commonly used innodb data. Since I don't have the mysql config I made for my last work, I forget all the innodb_ configuration options.