apache and mysql too many connections

ITCity
ITCity used Ask the Experts™
on
I am getting this error.

Warning: mysql_pconnect() [function.mysql-pconnect]: Too many connections in /usr/local/www/data/site/merchant/functions/incl_mysql.php on line 42

Error connecting to localhost #1040: Too many connections

How can i accept more localhost connections?

Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Senior Principal Technical Support Engineer
Top Expert 2009
Commented:
Two things - Don't use persistent connection (mysql_pconnect()) and set the MySQL system parameters such as wait_timeout and interactive_timeout to a low value rather than default 8Hrs.. this way The number of seconds the server waits for activity on a noninteractive connection before closing it.

This can be done..from MySQL prompt ( for making permanent you shud add these to config file)

SET GLOBAL wait_timeout=240;
SET GLOBAL wait_timeout=240;



To accept more connections..(better practice above thing rather than setting below)

SET GLOBAL max_connections=500;
1. try to replace mysql_pconnect with mysql_connect
if that dos not work ...
2. try to increase the max connections in php.ini

Commented:
edit /etc/mysql/my.cnf

change or add this value :

max_connections = 100

How to Generate Services Revenue the Easiest Way

This Tuesday! Learn key insights about modern cyber protection services & gain practical strategies to skyrocket business:

- What it takes to build a cloud service portfolio
- How to determine which services will help your unique business grow
- Various use-cases and examples

UmeshSenior Principal Technical Support Engineer
Top Expert 2009
Commented:
Sorry... seems SET GLOBAL wait_timeout=240; repeated twice

SET GLOBAL wait_timeout=240;
SET GLOBAL interactive_timeout=240;

Commented:
mysql_pconnect is fastest since the server can handle enough threads.

Using pconnect, the best value of mysql max_connections is a bit more higher than the apache MaxClients value.
For apache2, find it in /etc/apache2/apache2.conf

Author

Commented:
Inside php.ini this is what i have for mysql.  What changes do I make here?  

Thanks
[MySQL]
; Allow or prevent persistent links.
mysql.allow_persistent = On
 
; Maximum number of persistent links.  -1 means no limit.
mysql.max_persistent = -1
 
; Maximum number of links (persistent + non-persistent).  -1 means no limit.
mysql.max_links = -1
 
; Default port number for mysql_connect().  If unset, mysql_connect() will use
; the $MYSQL_TCP_PORT or the mysql-tcp entry in /etc/services or the
; compile-time value defined MYSQL_PORT (in that order).  Win32 will only look
; at MYSQL_PORT.
mysql.default_port =
 
; Default socket name for local MySQL connects.  If empty, uses the built-in
; MySQL defaults.
mysql.default_socket =
 
; Default host for mysql_connect() (doesn't apply in safe mode).
mysql.default_host =
 
; Default user for mysql_connect() (doesn't apply in safe mode).
mysql.default_user =
 
; Default password for mysql_connect() (doesn't apply in safe mode).
; Note that this is generally a *bad* idea to store passwords in this file.
; *Any* user with PHP access can run 'echo get_cfg_var("mysql.default_password")
; and reveal this password!  And of course, any users with read access to this
; file will be able to reveal the password as well.
mysql.default_password =
 
; Maximum time (in seconds) for connect timeout. -1 means no limit
mysql.connect_timeout = 60
 
; Trace mode. When trace_mode is active (=On), warnings for table/index scans and
; SQL-Errors will be displayed.
mysql.trace_mode = Off
 
[MySQLi]
 
; Maximum number of links.  -1 means no limit.
mysqli.max_links = -1
 
; Default port number for mysqli_connect().  If unset, mysqli_connect() will use
; the $MYSQL_TCP_PORT or the mysql-tcp entry in /etc/services or the
; compile-time value defined MYSQL_PORT (in that order).  Win32 will only look
; at MYSQL_PORT.
mysqli.default_port = 3306
 
; Default socket name for local MySQL connects.  If empty, uses the built-in
; MySQL defaults.
mysqli.default_socket =
 
; Default host for mysql_connect() (doesn't apply in safe mode).
mysqli.default_host =
 
; Default user for mysql_connect() (doesn't apply in safe mode).
mysqli.default_user =
 
; Default password for mysqli_connect() (doesn't apply in safe mode).
; Note that this is generally a *bad* idea to store passwords in this file.
; *Any* user with PHP access can run 'echo get_cfg_var("mysqli.default_pw")
; and reveal this password!  And of course, any users with read access to this
; file will be able to reveal the password as well.
mysqli.default_pw =
 
; Allow or prevent reconnect
mysqli.reconnect = Off
 
[mSQL]
; Allow or prevent persistent links.
msql.allow_persistent = On
 
; Maximum number of persistent links.  -1 means no limit.
msql.max_persistent = -1
 
; Maximum number of links (persistent+non persistent).  -1 means no limit.
msql.max_links = -1

Open in new window

Author

Commented:
edit /etc/mysql/my.cnf

i could not locate this file here..  How can I locate this file?

thanks
UmeshSenior Principal Technical Support Engineer
Top Expert 2009

Commented:
run below command or just search using find command.. this should be in /etc/my.cnf

locate my.cnf

For time being you can set it dynamically as I shown in one of my earlier comments

Author

Commented:
I do not use that my.cnf.  Not in my Freebsd server.

thanks

Author

Commented:
i got nothing from locate.mycnf.  I think that is for windows servers

Commented:
find / -iname "my.cnf"
UmeshSenior Principal Technical Support Engineer
Top Expert 2009

Commented:
Try  this.. if there is no my.cnf on your box..create a sample my.cnf file and under [mysqld] group add the settings which told you i.e

[mysqld]
wait_timeout=240
interactive_timeout=240
max_connections=200

this can be used on linux....

locate my.cnf                

on windows MySQ: config file name is my.ini

Author

Commented:
I got a blank out put for that command as well.
UmeshSenior Principal Technical Support Engineer
Top Expert 2009

Commented:
No issues... it seems you have t create one file..


vi /etc/my.cnf  and add below line to this file and retsrat MySQL

[mysqld]
wait_timeout=240
interactive_timeout=240
max_connections=200

Commented:
On freebsd it seems to be located in /usr/local/etc/my.cnf
And by default, the file is not created.

After creating the my.cnf file, restart mysql :

/usr/local/etc/rc.d/mysql-server restart

Author

Commented:
I made a file called my.cnf and i pasted the following:

[mysqld]
wait_timeout=240
interactive_timeout=240
max_connections=200

I did a /usr/local/etc/rc.d/mysql-server restart

and i got this error:

error: Found option without preceding group in config file: /etc/my.cnf                                 at line: 1
Fatal error in defaults handling. Program aborted
error: Found option without preceding group in config file: /etc/my.cnf at line:                                 1
Fatal error in defaults handling. Program aborted

Author

Commented:
Does anyone know how to add more connections to mysql?

Commented:
Please, post your entire my.cnf file here.

Author

Commented:
I do not have a my.cnf.   How do I make one?

Author

Commented:
I made a cnf file.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial