SQLSTATE Too many connections

Had this error a week or two ago on the SQL database in FreePBX. Any quick resolution that anyone can fill me in on? Not terribly familiar with SQL administration.

System failed with following error messages:
Exception: SQLSTATE[08004] [1040] Too many connections::SQLSTATE[08004] [1040] Too many connections in file /var/www/html/admin/libraries/utility.functions.php on line 202
Stack trace:

  1. Exception->() /var/www/html/admin/libraries/utility.functions.php:202
  2. die_freepbx() /var/www/html/admin/libraries/BMO/Database.class.php:136
  3. PDOException->() /var/www/html/admin/libraries/BMO/Database.class.php:133
  4. PDO->__construct() /var/www/html/admin/libraries/BMO/Database.class.php:133
  5. FreePBX\Database->__construct() /var/www/html/admin/libraries/BMO/FreePBX.class.php:69
  6. FreePBX->__construct() /var/www/html/admin/bootstrap.php:141
  7. require_once() /etc/freepbx.conf:9
  8. include_once() /var/lib/asterisk/bin/fwconsole:12
    Exception: SQLSTATE[08004] [1040] Too many connections::SQLSTATE[08004] [1040] Too many connections in file /var/www/html/admin/libraries/utility.functions.php on line 202
    Stack trace:
  9. Exception->() /var/www/html/admin/libraries/utility.functions.php:202
  10. die_freepbx() /var/www/html/admin/libraries/BMO/Database.class.php:136
  11. PDOException->() /var/www/html/admin/libraries/BMO/Database.class.php:133
  12. PDO->__construct() /var/www/html/admin/libraries/BMO/Database.class.php:133
  13. FreePBX\Database->__construct() /var/www/html/admin/libraries/BMO/FreePBX.class.php:69
  14. FreePBX->__construct() /var/www/html/admin/bootstrap.php:141
  15. require_once() /etc/freepbx.conf:9
  16. include_once() /var/lib/asterisk/bin/fwconsole:12

I’m having the same isse today. How did you resolve this problem?
Thanks.

Hello @ken315,

You need to set a bigger value in the max_connections (deafult 100) setting in the /etc/my.cnf file.

Under the [mysqld] section add the following setting:

max_connections = 200

Restart the mysql service: service mysqld restart.

Thank you,

Daniel Friedman
Trixton LTD.

You have to find out why you are getting those connections and who is connected.

From the mysql/maria cli

show processlist;

anything more than a very few is probably a bad thing, and the ones there should be identifiable.

@danielf, thanks, it works.

@dicko, thanks for the suggestion. However, I’m a newbie. Do you mind giving me step by step instructions on how to show the process list? And if I noticed something that is not identifiable, what can I do? thanks.

Mysql maintains a processlist of all connections made to the engine, what I posted would list them. Expect a connection to the asteriskcdrdb from Asterisk as it is dynamic, expect a connection from FreePBX when it updates something, any other connection unless you have something custom running, which I assume you would know about, is VERY suspect.

dickos right. It would be good to understand what’s using all those connections. For reference, I have quite a few boxes that run thousands of calls and the connections really never go above 5-6 (unless I’m doing something very custom).

Assuming you are on MySql. Typing mysql in the Linux terminal would get you to where you could run the processlist.