简体   繁体   中英

MySQL: “Too many connections” in opencart

I recently installed opencart 2.0.3.1. Since I have installed opencart I get the below error

Warning: mysqli::mysqli() [mysqli.mysqli]: (08004/1040): Too many connections in /home/burhanie/public_html/store/system/library/db/mysqli.php on line 7

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

Warning: mysqli::close() [mysqli.close]: Couldn't fetch mysqli in /home/burhanie/public_html/store/system/library/db/mysqli.php on line 58

Below is the opencart code from file mysqli.php

    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. which states opencart is using too many connection. This seems to be a bug

在此处输入图片说明

Verify the max_connections in the Configuration and change it local AND in the /etc/my.cnf

SHOW VARIABLES LIKE 'max_connections';

SET GLOBAL max_connections = 200;

Just increasing max_connections is not the solution.

As per your mysqladmin suggestions, you need to optimize your queries as well db configuration.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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