Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+2 votes
30.1k views
in Q2A Core by
[23-Dec-2010 18:22:03] PHP Warning:  mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: User db_admin already has more than 'max_user_connections' active connections in /home/public_html/qa-include/qa-db.php on line 50

2 Answers

+1 vote
by
I don't think so. I think it can happen if too many pages are requested from your Q2A system at the same time, presumably by multiple users and/or search engines. But if this happens often it might be worth checking into in more detail.
by
yeah, traffic was bit high. If it appears again then will let you know.
0 votes
by
yesterday again I got this error when users were more than 100 at a time on the site. why it should happen?
by
If you have persistent MySQL connections running elsewhere on the site, then it can cause problems when opening regular connections (because all the connections are used up by persistent ones). I had this with CodeIgniter, you just need to tell it to use regular MySQL connections.

You might also be able to increase the maximum number of connections that MySQL will open on your server.
by
I'm running only Q2A on the site with MySQL database.

Do I still need to increase maximum number of mysql connections? if yes, where I need to make these changes?
by
Now a days this is happening very frequently. pls suggest some solution. Thanks!
by
What type of hosting are you on? Shared, VPS, Dedicated etc. To increase the number of connections you need to change the number in the my.cnf file. If you don't have access to the server you'll need to get your host to do it for you.

Aside from that perhaps look into more database/query caching?
by
Also, if you are on shared hosting it could easily be a different site causing all the problems. Check with your host or get better hosting.
by
Many thanks!
I'm with shared hosting service, Bluehost. I will contact their support team to look into this issue. I guess there is nothing needs to be done from my side. It might be some other sites causing this issue.
by
These are setting of mysql in php.ini ...do they look fine?

[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
by
Here is reply which I got from the bluehost customer support team

-----------
On our system, the maximum amount of concurrent connections that a single user can have open is 15. It seems as though your connections are either staying open too long, or the queries that run in those connection are taking too long to execute. I would recommend two things:
1. Looking through your MySQL Slow Queries. This will show you specifically where (if any), query problems exist. The MySQL Slow Query logs can be found in ~/tmp/mysql_slow_queries you can access them via FTP or in the File Manager on your cPanel.

2. Implementing a caching system. On most database driven sites, the database is queried multiple times on every page load to return data. The majority of these queries are returning the same information time after time. A caching system will store the information returned from your database and use it for a set period of time without querying the database again. Not only will this cut down by a long ways on MySQL connections, it will also make your site load much faster since MySQL is not as involved.
------------------
by
There could be an issue that pages are taking a long time to generate, so that the database connection for each page view is open a long time, leading to high concurrent connections.

You can find out more by changing this line in your qa-config.php file:

define('QA_DEBUG_PERFORMANCE', false);

... to ...

define('QA_DEBUG_PERFORMANCE', $_SERVER['HTTP_HOST']=='1.2.3.4');

Replace 1.2.3.4 with your IP address, which you can find out from www.whatismyip.com. Now as you browse your site, you will see information at the bottom of the page showing how long it took to generate each page, and how that is broken up into different stages and types of operation. Have a look and see if one thing really dominates the processing time.
by
Gideon, Thanks for the suggestion. will do this experiment to find out root cause.

I feel, just a 15 connections is a bottle neck.
by
It could be the timeout. On my server reducing the timeout on Apache connections got rid of lag, maybe the same theory works for MySQL. It's possible all connections to the site are staying around for too long after being opened and not being able to be used by others.
...