股票

建立数据库连接时出错

网站经常会出现这个问题,进后台一看,mysql被终止了。具体有两方面的原因:

原因一是数据库最大连接数太多,同时访问的进程多时,每多一个访问进程,CPU就给网站分配一个线程,同时占用相应内存,当并发数很多时,内存溢出,服务器就会把占用内存最大的进程杀死,于是mysql躺枪了。

详见:apache内存占用过大

 

原因二是数据库配置有问题

查询 mysql 的错误日志/var/log/mysqld.err ,发现有如下提示

150923 14:50:40 [Note] Plugin ‘FEDERATED’ is disabled.

150923 14:50:40 InnoDB: The InnoDB memory heap is disabled

150923 14:50:40 InnoDB: Mutexes and rw_locks use GCC atomic builtins

150923 14:50:40 InnoDB: Compressed tables use zlib 1.2.7

150923 14:50:40 InnoDB: Using Linux native AIO

150923 14:50:41 InnoDB: Initializing buffer pool, size = 128.0M

InnoDB: mmap(137363456 bytes) failed; errno 12

150923 14:50:41 InnoDB: Completed initialization of buffer pool

150923 14:50:41 InnoDB: Fatal error: cannot allocate memory for the buffer pool

150923 14:50:41 [ERROR] Plugin ‘InnoDB’ init function returned error.

150923 14:50:41 [ERROR] Plugin ‘InnoDB’ registration as a STORAGE ENGINE failed.

150923 14:50:41 [ERROR] Unknown/unsupported storage engine: InnoDB

150923 14:50:41 [ERROR] Aborting

发现是InnoDB范围出错,在 /etc/mysql/my.cnf 中添加 innodb_buffer_pool_size = 64

重新定义范围后,暂时不会出现mysql总是死掉的问题了。

打赏
原文链接:,转发请注明来源!

发表评论