mysqli too many connections (HY000/1040) and (08004/1040) is there a difference?

"Too many connections" indicates, that your script is opening at least more than one connection to the database. Basically, to one server, only one connection is needed. Getting this error is either a misconfiguration of the server (which I assume isn't the case because max connections = zero isn't an option) or some programming errors in your script.

Check for re-openings of your database connections (mysqli_connect). There should only be one per script (!) and usually you should take care of reusing open connections OR close them properly after script execution (mysqli_close)


Steps to resolve that issue:

  1. Check MySQL connection limit in configuration file or my.cnf
  2. Run below command to check:

    mysql -e "show variables like '%connection%';"
    
  3. You will see like this:

    max_connections = 500
    
  4. Increase it as per you want:

    max_connections = 50000
    
  5. Restart the MySQL service:

    $ service MySQL restart
    

Now check your website, I hope the error will not occur!

Thank You!

Tags:

Mysql

Php

Mysqli