Getting Error: Warning: mysql_connect() [function.mysql-connect]: Too many connections in

Mobile
feeds
Welcome Login | Register


Getting Error: Warning: mysql_connect() [function.mysql-connect]: Too many connections in
Getting Error: Warning: mysql_connect() [function.mysql-connect]: Too many connections in This page contains information about Getting Error: Warning: mysql_connect() [function.mysql-connect]: Too many connections in Here you can also give your thought about the subject of Getting Error: Warning: mysql_connect() [function.mysql-connect]: Too many connections in


Main List


Getting Error: Warning: mysql_connect() [function.mysql-connect]: Too many connections in

By: Administration

The other day a customer reported trouble with their site. The error they were getting was:

Warning: mysql_connect() [function.mysql-connect]: Too many connections in

I am not sure what really fixed it but this is what I did.

  • I logged into phpmyadmin with the root user. In the Processes tab, i killed all processes
  • Rebooted by httpd server
  • Rebooted my mysqld server. I shut it down for like 5 minutes, then start it back up.
  • I put mysql_close() at the end of every mysql_connect() script. mainli on the footer file.

Since then, I haven't seen the error.

- UPDATE: I wanted to know more about this error. In researching I found out what was causing this error. the guilty one was Google. At the time I was getting this error, Google was crawling my site. I was able to find like 15 diffrent Google IP's crawling my site at the same time, which cause an overload on my server. I also added the following code at the end of my scrpt to make sure I close all mysql connection on every page:

mysql_close($mysql_connection);

* $mysql_connection = whatever variable you use to connect to your mysql. 

 


 

More info:

whenever you connect to you database make sure at the end of the script / function / run you close the connection. I use OO connections always labelled $DB and then use $DB->close(); to get rid of the connection, it is most probable that you have not closed connections at some point and this has led to the problem.

 

You're really going to have to analyse the load on your web servers / database servers more. Log in to MySQL as root and use "show processlist" to see all the connections at any given time. Consider increasing the maximum, or reducing your usage of connections.

Try not to open more than one database connection in each PHP script. Don't use persistent connections unless you know that you can handle one connection per Apache thread per persistent connection.

You really need to analyse what's causing these connections to be made.

Remember that in principle each web server thread could use one connection at once for each one you open.

 


f you are receiving a mysql_connect error on your web site, such as the one listed below,

Warning: mysql_connect() [function.mysql-connect]: Too many connections in /imedia/users/user/htdocs/connect.php on line 7

you may want to consider making some modifications to your code, per the PHP.NET Manual, to resolve these errors.

Using mysql_connect(): The advantage of using mysql_connect() for connections to MySQL databases in your code is that the link to the server will be closed as soon as the execution of the script ends, unless it's closed earlier by explicitly calling mysql_close().

More information can be found at the following URL:
http://us3.php.net/manual/en/function.mysql-connect.php

Using mysql_close(): This explicitly closes the connections. The use of mysql_close() in conjunction with mysql_connect() would ensure that the connection is closed.

Using mysql_pconnect(): This has a disadvantage in that the connection to the MySQL server will not be closed when the execution of the script ends. Instead, the link will remain open for future use. While this will work if you need to leave the connection open for additional connections, mysql_close() will not close links established by mysql_pconnect().

More information can be found at the following URL:
http://us3.php.net/manual/en/function.mysql-pconnect.php


Posted on: Jun 12, 2006
Your Name
Your Email Address (Will Not Be Published)
Your Comments

# 104331 Reply By apuli On Mon May 25, 2009 5:37 pm
apuli
i was getting this error on my oscommerce script but it turned out that it was some ip address was causing all the problems.

it was ip address: 74.125.45.100

well, if you check that ip, it belongs to google so yeah, it turned out to be that a spider bot was indexing my site and that was causing all the overload on my server.

thanks