Wordpress错误建立数据库连接 - 内存问题

时间:2016-03-17 20:09:47

标签: mysql wordpress

我已经运行这个wordpress网站很长一段时间没有任何问题,但最近得到错误“建立数据库连接时出错”。如果我重新启动mySQL,问题会暂时解决,但很快就会回来。

查看MySQL日志文件后,我认为问题是由于某种内存泄漏,但是我无法找到问题的根源。

我已经读过问题可能来自未配置的交换文件,但我已按如下方式配置交换:

             total       used       free     shared    buffers     cached
Mem:           987        968         18         26         18        137
-/+ buffers/cache:        812        175
Swap:          255         35        220

如果有人能帮我理解这个日志文件,那真是太棒了。

MySQL日志文件:

2016-03-17 06:48:45 3575 [Warning] Using unique option prefix myisam-recover instead of myisam-recover-options is deprecated and will be removed in a future release. Please use the full name instead.
2016-03-17 06:48:45 3575 [Note] Plugin 'FEDERATED' is disabled.
2016-03-17 06:48:45 3575 [ERROR] Function 'innodb' already exists
2016-03-17 06:48:45 3575 [Warning] Couldn't load plugin named 'innodb' with soname 'ha_innodb.so'.
2016-03-17 06:48:45 3575 [ERROR] Function 'federated' already exists
2016-03-17 06:48:45 3575 [Warning] Couldn't load plugin named 'federated' with soname 'ha_federated.so'.
2016-03-17 06:48:45 3575 [ERROR] Function 'blackhole' already exists
2016-03-17 06:48:45 3575 [Warning] Couldn't load plugin named 'blackhole' with soname 'ha_blackhole.so'.
2016-03-17 06:48:45 3575 [ERROR] Function 'archive' already exists
2016-03-17 06:48:45 3575 [Warning] Couldn't load plugin named 'archive' with soname 'ha_archive.so'.
2016-03-17 06:48:45 3575 [Note] InnoDB: Using atomics to ref count buffer pool pages
2016-03-17 06:48:45 3575 [Note] InnoDB: The InnoDB memory heap is disabled
2016-03-17 06:48:45 3575 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2016-03-17 06:48:45 3575 [Note] InnoDB: Memory barrier is not used
2016-03-17 06:48:45 3575 [Note] InnoDB: Compressed tables use zlib 1.2.8
2016-03-17 06:48:45 3575 [Note] InnoDB: Using Linux native AIO
2016-03-17 06:48:45 3575 [Note] InnoDB: Using CPU crc32 instructions
2016-03-17 06:48:45 3575 [Note] InnoDB: Initializing buffer pool, size = 128.0M
InnoDB: mmap(137363456 bytes) failed; errno 12
2016-03-17 06:48:45 3575 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
2016-03-17 06:48:45 3575 [ERROR] Plugin 'InnoDB' init function returned error.
2016-03-17 06:48:45 3575 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2016-03-17 06:48:45 3575 [ERROR] Unknown/unsupported storage engine: InnoDB
2016-03-17 06:48:45 3575 [ERROR] Aborting

2016-03-17 06:48:45 3575 [Note] Binlog end
2016-03-17 06:48:45 3575 [Note] Shutting down plugin 'partition'
2016-03-17 06:48:45 3575 [Note] Shutting down plugin 'BLACKHOLE'
2016-03-17 06:48:45 3575 [Note] Shutting down plugin 'ARCHIVE'
2016-03-17 06:48:45 3575 [Note] Shutting down plugin 'PERFORMANCE_SCHEMA'
2016-03-17 06:48:45 3575 [Note] Shutting down plugin 'INNODB_SYS_DATAFILES'
2016-03-17 06:48:45 3575 [Note] Shutting down plugin 'INNODB_SYS_TABLESPACES'
2016-03-17 06:48:45 3575 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN_COLS'
2016-03-17 06:48:45 3575 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN'
2016-03-17 06:48:45 3575 [Note] Shutting down plugin 'INNODB_SYS_FIELDS'
2016-03-17 06:48:45 3575 [Note] Shutting down plugin 'INNODB_SYS_COLUMNS'
2016-03-17 06:48:45 3575 [Note] Shutting down plugin 'INNODB_SYS_INDEXES'
2016-03-17 06:48:45 3575 [Note] Shutting down plugin 'INNODB_SYS_TABLESTATS'
2016-03-17 06:48:45 3575 [Note] Shutting down plugin 'INNODB_SYS_TABLES'
2016-03-17 06:48:45 3575 [Note] Shutting down plugin 'INNODB_FT_INDEX_TABLE'
2016-03-17 06:48:45 3575 [Note] Shutting down plugin 'INNODB_FT_INDEX_CACHE'
2016-03-17 06:48:45 3575 [Note] Shutting down plugin 'INNODB_FT_CONFIG'
2016-03-17 06:48:45 3575 [Note] Shutting down plugin 'INNODB_FT_BEING_DELETED'
2016-03-17 06:48:45 3575 [Note] Shutting down plugin 'INNODB_FT_DELETED'
2016-03-17 06:48:45 3575 [Note] Shutting down plugin 'INNODB_FT_DEFAULT_STOPWORD'
2016-03-17 06:48:45 3575 [Note] Shutting down plugin 'INNODB_METRICS'
2016-03-17 06:48:45 3575 [Note] Shutting down plugin 'INNODB_BUFFER_POOL_STATS'
2016-03-17 06:48:45 3575 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE_LRU'
2016-03-17 06:48:45 3575 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE'
2016-03-17 06:48:45 3575 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX_RESET'
2016-03-17 06:48:45 3575 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX'
2016-03-17 06:48:45 3575 [Note] Shutting down plugin 'INNODB_CMPMEM_RESET'
2016-03-17 06:48:45 3575 [Note] Shutting down plugin 'INNODB_CMPMEM'
2016-03-17 06:48:45 3575 [Note] Shutting down plugin 'INNODB_CMP_RESET'
2016-03-17 06:48:45 3575 [Note] Shutting down plugin 'INNODB_CMP'
2016-03-17 06:48:45 3575 [Note] Shutting down plugin 'INNODB_LOCK_WAITS'
2016-03-17 06:48:45 3575 [Note] Shutting down plugin 'INNODB_LOCKS'
2016-03-17 06:48:45 3575 [Note] Shutting down plugin 'INNODB_TRX'
2016-03-17 06:48:45 3575 [Note] Shutting down plugin 'CSV'
2016-03-17 06:48:45 3575 [Note] Shutting down plugin 'MEMORY'
2016-03-17 06:48:45 3575 [Note] Shutting down plugin 'MRG_MYISAM'
2016-03-17 06:48:45 3575 [Note] Shutting down plugin 'MyISAM'
2016-03-17 06:48:45 3575 [Note] Shutting down plugin 'sha256_password'
2016-03-17 06:48:45 3575 [Note] Shutting down plugin 'mysql_old_password'
2016-03-17 06:48:45 3575 [Note] Shutting down plugin 'mysql_native_password'
2016-03-17 06:48:45 3575 [Note] Shutting down plugin 'binlog'
2016-03-17 06:48:45 3575 [Note] /usr/sbin/mysqld: Shutdown complete

2016-03-17 06:48:46 3606 [Warning] Using unique option prefix myisam-recover instead of myisam-recover-options is deprecated and will be removed in a future release. Please use the full name instead.
2016-03-17 06:48:46 3606 [Note] Plugin 'FEDERATED' is disabled.
2016-03-17 06:48:46 3606 [ERROR] Function 'innodb' already exists
2016-03-17 06:48:46 3606 [Warning] Couldn't load plugin named 'innodb' with soname 'ha_innodb.so'.
2016-03-17 06:48:46 3606 [ERROR] Function 'federated' already exists
2016-03-17 06:48:46 3606 [Warning] Couldn't load plugin named 'federated' with soname 'ha_federated.so'.
2016-03-17 06:48:46 3606 [ERROR] Function 'blackhole' already exists
2016-03-17 06:48:46 3606 [Warning] Couldn't load plugin named 'blackhole' with soname 'ha_blackhole.so'.
2016-03-17 06:48:46 3606 [ERROR] Function 'archive' already exists
2016-03-17 06:48:46 3606 [Warning] Couldn't load plugin named 'archive' with soname 'ha_archive.so'.
2016-03-17 06:48:46 3606 [Note] InnoDB: Using atomics to ref count buffer pool pages
2016-03-17 06:48:46 3606 [Note] InnoDB: The InnoDB memory heap is disabled
2016-03-17 06:48:46 3606 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2016-03-17 06:48:46 3606 [Note] InnoDB: Memory barrier is not used
2016-03-17 06:48:46 3606 [Note] InnoDB: Compressed tables use zlib 1.2.8
2016-03-17 06:48:46 3606 [Note] InnoDB: Using Linux native AIO
2016-03-17 06:48:46 3606 [Note] InnoDB: Using CPU crc32 instructions
2016-03-17 06:48:46 3606 [Note] InnoDB: Initializing buffer pool, size = 128.0M
InnoDB: mmap(137363456 bytes) failed; errno 12
2016-03-17 06:48:46 3606 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
2016-03-17 06:48:46 3606 [ERROR] Plugin 'InnoDB' init function returned error.
2016-03-17 06:48:46 3606 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2016-03-17 06:48:46 3606 [ERROR] Unknown/unsupported storage engine: InnoDB
2016-03-17 06:48:46 3606 [ERROR] Aborting

2 个答案:

答案 0 :(得分:0)

服务器内存有问题。从您的MySQL日志文件中我们可以得到InnoDb插件由于无法Initializing buffer pool而无法启动。所以任何带有InnoDb存储的表都会导致错误。

您的解决方案

  

如果我重启mySQL,问题会暂时解决,但很快就会回来。

有效,因为重启Mysql后会得到一些空闲内存。

2016-03-17 06:48:46 3606 [Note] InnoDB: Initializing buffer pool, size = 128.0M
InnoDB: mmap(137363456 bytes) failed; errno 12
2016-03-17 06:48:46 3606 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
2016-03-17 06:48:46 3606 [ERROR] Plugin 'InnoDB' init function returned error.
2016-03-17 06:48:46 3606 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2016-03-17 06:48:46 3606 [ERROR] Unknown/unsupported storage engine: InnoDB
2016-03-17 06:48:46 3606 [ERROR] Aborting

答案 1 :(得分:0)

alexander.polomodov走在正确的轨道上,但我猜你需要更改的配置是MPM-Prefork配置中的MaxRequestWorkers(或旧Apache系统上的MaxClients)。

您可以使用Apache2Buddy对Apache配置运行诊断。它将根据您拥有的RAM量和应用程序的大小来计算您可以运行的Apache Workers数量: $ curl -L http://apache2buddy.pl/ | perl

只需将值更新为Apache2推荐的值(配置在我的系统上/etc/apache2/mods-available/mpm_prefork.conf)。在那之后,只需重新启动Apache,你就应该好了。

如果您的网站没有处理大量流量,您可能会被机器人击中。检查您的Apache访问日志$ cat /var/log/apache2/access.log

如果您想要更深入的解释,压力测试的方法或者如何阻止某些机器人流量的想法,我写了一篇关于这种情况的文章:http://brunzino.github.io/blog/2016/05/21/solution-how-to-debug-intermittent-error-establishing-database-connection/