Mysql cannot allocate memory for the buffer pool solution

Further optimize the reference documentation for problem cause resolution

Cause of the problem
Last night, I modified the database and added a “FULLTEXT” index for the field. However, this morning, I found that the database could not be connected and could not be restarted. So I checked the log file:

cat /var/log/mysqld.log

The following error log was found:

130728  6:50:14 InnoDB: Initializing buffer pool, size = 128.0M
InnoDB: mmap(137363456 bytes) failed; errno 12
130728  6:50:14 InnoDB: Completed initialization of buffer pool
130728  6:50:14 InnoDB: Fatal error: cannot allocate memory for the buffer pool

The short answer is that there is no way to allocate 128M memory for mysql’s Buffer pool.
reason is obvious, the lack of memory, after looking up data found that the original parameter is mainly used to cache innodb table index, data, the buffer when inserting data. My server only has 1 gb of memory, so this parameter crashed mysql when it started allocating the cache for the index.
The solution
The configurations for mysql are inside /ect/ mysqlt.cnf (the Ubuntu directory is slightly different, where you can find it using whereis my.cnf).

vim /etc/my.cnf

You can see the fourth line:

#innodb_buffer_pool_size = 128M

The default configuration shown here is 128M, which is the annotation status. We just need to remove the annotation and change 128 to a smaller size (depending on your personal situation). I will change it to:

innodb_buffer_pool_size = 50M

That’s about it.
Further optimization
Generally appear this kind of problem students, the memory is certainly not large, so we can set swap partition, which is often said virtual memory.
is illustrated the role of the swap here won’t do, simply means can assist Mem points of memory.
direct code:

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

Finally, add the code /swapfile swap swap defaults 0 0 to the /etc/fstab file.

free

If you can see Mem and SWAP, it’s successful.
and finally restart mysql.
Reference documentation
http://hongjiang.info/aliyun-vps-mysql-aborting/

Read More: