MySQL:opencart 中的“连接太多”

问题描述 投票:0回答:3

我最近安装了opencart 2.0.3.1。因为我已经安装了 opencart,所以出现以下错误

警告:mysqli::mysqli() [mysqli.mysqli]: (08004/1040): 第 7 行 /home/burhanie/public_html/store/system/library/db/mysqli.php 中的连接过多

注意:错误:无法建立数据库链接(1040)第 10 行 /home/burhanie/public_html/store/system/library/db/mysqli.php 中的连接过多

警告:mysqli::close() [mysqli.close]:无法在第 58 行的 /home/burhanie/public_html/store/system/library/db/mysqli.php 中获取 mysqli

下面是文件 mysqli.php 中的 opencart 代码

    public function __construct($hostname, $username, $password, $database,$port = '3306') {$this->link = new \mysqli($hostname, $username, $password, $database, $port);

if ($this->link->connect_error) {
    trigger_error('Error: Could not make a database link (' . $this->link->connect_errno . ') ' . $this->link->connect_error);
    exit();
}

$this->link->set_charset("utf8");
$this->link->query("SET SQL_MODE = ''");

}

下面是 phpmyadmin advisor 的屏幕截图。其中指出 opencart 使用了太多连接。这似乎是一个错误

php mysql opencart opencart2.x
3个回答
0
投票

验证配置中的 max_connections 并在本地和 /etc/my.cnf 中更改它

SHOW VARIABLES LIKE 'max_connections';

SET GLOBAL max_connections = 200;

0
投票

仅仅增加 max_connections 不是解决方案。

根据您的 mysqladmin 建议,您需要优化查询以及数据库配置。

一些主要问题是-

  1. 经常在磁盘上创建临时表。

  2. 联接不使用索引。

  3. key_buffer_size 似乎设置不正确。

由于上述原因,您的查询将花费更多时间并堆积在队列中而不是空闲连接,因此将使用所有连接并且在使用所有连接后将不允许新连接。

除了查询/数据库优化之外,您还需要检查您如何在应用程序中使用连接,以及应用程序是否正确关闭了连接。


-2
投票

我有同样的问题。但我仍然找不到解决方案。您能否提供有关此问题的更多提示。谢谢你的回复。

© www.soinside.com 2019 - 2024. All rights reserved.