MySQL:低内存机器配置

来自WHY42
imported>Soleverlee2017年1月12日 (四) 02:10的版本
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)

这几天发现本网站老是连不上数据库,查看日志:

170110  8:29:52 InnoDB: Initializing buffer pool, size = 128.0M
InnoDB: mmap(137756672 bytes) failed; errno 12
170110  8:29:52 InnoDB: Completed initialization of buffer pool
170110  8:29:52 InnoDB: Fatal error: cannot allocate memory for the buffer pool
170110  8:29:52 [ERROR] Plugin 'InnoDB' init function returned error.
170110  8:29:52 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
170110  8:29:52 [ERROR] mysqld: Out of memory (Needed 128917504 bytes)
170110  8:29:52 [ERROR] mysqld: Out of memory (Needed 96681984 bytes)
170110  8:29:52 [ERROR] mysqld: Out of memory (Needed 72499200 bytes)
170110  8:29:52 [Note] Plugin 'FEEDBACK' is disabled.
170110  8:29:52 [ERROR] Unknown/unsupported storage engine: InnoDB
170110  8:29:52 [ERROR] Aborting

正巧本人使用的就是AWS的免费EC2服务器,还有MariaDB。修改配置

[mysqld]
performance_schema = off

另外查看EC-2没有设置swap,需要设置swap:

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

添加到/etc/fstab

/swapfile swap swap defaults 0 0

如果需要更改innodb_buffer_pool_size

[mysqld]
innodb_buffer_pool_size=64M