Link to home
Start Free TrialLog in
Avatar of ITCity
ITCity

asked on

apache and mysql too many connections

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
ASKER CERTIFIED SOLUTION
Avatar of Umesh
Umesh
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of racmail2001
1. try to replace mysql_pconnect with mysql_connect
if that dos not work ...
2. try to increase the max connections in php.ini
edit /etc/mysql/my.cnf

change or add this value :

max_connections = 100

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Avatar of ITCity
ITCity

ASKER

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

Avatar of ITCity

ASKER

edit /etc/mysql/my.cnf

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

thanks
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
Avatar of ITCity

ASKER

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

thanks
Avatar of ITCity

ASKER

i got nothing from locate.mycnf.  I think that is for windows servers
find / -iname "my.cnf"
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
Avatar of ITCity

ASKER

I got a blank out put for that command as well.
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
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

Avatar of ITCity

ASKER

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
Avatar of ITCity

ASKER

Does anyone know how to add more connections to mysql?
Please, post your entire my.cnf file here.
Avatar of ITCity

ASKER

I do not have a my.cnf.   How do I make one?
Avatar of ITCity

ASKER

I made a cnf file.