技术饭
MySQL崩溃与致命错误:无法为缓冲池分配内存
我们有几个网站在运行,拥有1GB的实例。服务器运完美无暇运行5个月,然后MySQL开始崩溃,每隔几天,mysql错误日志中出现以下错误。
170901 21:08:59 mysqld_safe Number of processes running now: 0
170901 21:08:59 mysqld_safe mysqld restarted
170901 21:08:59 InnoDB: Initializing buffer pool, size = 8.0M
170901 21:08:59 InnoDB: Completed initialization of buffer pool
170901 21:08:59 InnoDB: Started; log sequence number 0 44233
170901 21:08:59 [Note] Event Scheduler: Loaded 0 events
170901 21:08:59 [Note] /usr/libexec/mysqld: ready for connections.
Version: '5.1.73' socket: '/var/lib/mysql/mysql.sock' port: 3306 Source distribution
尝试重新启动MySQL服务时,我们收到以下错误:
# service mysqld start
ERROR 2002 (HY000): Can't connect to local MySQL server
through socket '/var/run/mysqld/mysqld.sock' (111)
问题是服务器没有足够的内存分配给MySQL进程。这个问题有几个解决方案。
(1)增加物理RAM。添加1GB的额外RAM可以解决问题。
(2)分配SWAP空间。默认情况下,Digital Ocean VPS实例未配置为使用交换空间。通过分配512MB的交换空间,我们可以解决这个问题。要将交换空间添加到服务器,请按照以下步骤操作:
##作为root用户,执行以下操作:
#dd if = / dev / zero of = / swap.dat bs = 1024 count = 512M
#mkswap /swap.dat#swapon
/swap.dat
##编辑/ etc / fstab和以下条目。
/swap.dat none swap sw 0 0
(3)减小MySQL缓冲池大小的大小
##编辑/etc/my.cnf,并在[mysqld]标题下添加以下行。
[mysqld]
innodb_buffer_pool_size = 64M
Restart mysql and you're good to go. You'll have to continuously monitor MySQL process for a week or two to ensure that the server is running without memory allocation problem.
文明上网理性发言!