简体   繁体   English

MySQL:opencart中的“连接过多”

[英]MySQL: “Too many connections” in opencart

I recently installed opencart 2.0.3.1. 我最近安装了opencart 2.0.3.1。 Since I have installed opencart I get the below error 由于我已经安装了opencart,因此出现以下错误

Warning: mysqli::mysqli() [mysqli.mysqli]: (08004/1040): Too many connections in /home/burhanie/public_html/store/system/library/db/mysqli.php on line 7 警告:mysqli :: mysqli()[mysqli.mysqli]:(08004/1040):在第7行的/home/burhanie/public_html/store/system/library/db/mysqli.php中的连接太多

Notice: Error: Could not make a database link (1040) Too many connections in /home/burhanie/public_html/store/system/library/db/mysqli.php on line 10 注意:错误:无法建立数据库链接(1040)/home/burhanie/public_html/store/system/library/db/mysqli.php中第10行的连接太多

Warning: mysqli::close() [mysqli.close]: Couldn't fetch mysqli in /home/burhanie/public_html/store/system/library/db/mysqli.php on line 58 警告:mysqli :: close()[mysqli.close]:无法在第58行的/home/burhanie/public_html/store/system/library/db/mysqli.php中获取mysqli

Below is the opencart code from file mysqli.php 以下是来自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 = ''");

} }

Below is the screen shot of phpmyadmin advisor. 下面是phpmyadmin顾问的屏幕截图。 which states opencart is using too many connection. 哪个状态表明opencart正在使用太多连接。 This seems to be a bug 这似乎是一个错误

在此处输入图片说明

Verify the max_connections in the Configuration and change it local AND in the /etc/my.cnf 验证配置中的max_connections并在/etc/my.cnf中对其进行本地AND更改

SHOW VARIABLES LIKE 'max_connections';

SET GLOBAL max_connections = 200;

Just increasing max_connections is not the solution. 仅增加max_connections不是解决方案。

As per your mysqladmin suggestions, you need to optimize your queries as well db configuration. 根据您的mysqladmin建议,您需要优化查询以及数据库配置。

Some main issues are- 一些主要问题是-

  1. frequently temp tables are creating on disk. 临时表经常在磁盘上创建。

  2. Joins are not using index. 联接不使用索引。

  3. key_buffer_size seems not set properly. key_buffer_size似乎设置不正确。

Due to above reasons your queries will take more time and pile up in queue and not free connections, so all connections will be used and after using all connections it will not allow for new connections. 由于上述原因,您的查询将花费更多时间并排在队列中,而不是没有空闲的连接,因此将使用所有连接,并且在使用所有连接后将不允许新连接。

along with query/db optimization you also need to check how you are using connections in your application and connections are closing properly by application or not. 除了查询/数据库优化外,您还需要检查如何在应用程序中使用连接,以及连接是否按应用正确关闭。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM