53

I have a server where a lot of users will connect to it and use a database there, and I am using MySQL. I know that the default number of max_connections in MySQL is 100 or 150 but I am sure I need way beyond that number, therefore I used the following to increase the number:

SET global max_connections = 1000000

Now I try to check the max_connections as follows:

show variables like 'max_connections'

It gives me the following:

max_connections; 100000;

Which is a sign that it succeeded (unless I am understanding it wrong). When my users start to connect I am receiving an error from the server when the number of connected users exceeds 110. The error is:

error connecting: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.

Why am I getting this error, and how to fix it?

5
  • I don't think you can change max_connections programmatically because changing that max requires a server restart. Maybe you could, but probably shouldn't...? Nov 14, 2013 at 21:00
  • Hmm, you mean I should do the start-up setup of MySQL and select the settings from there?
    – antf
    Nov 14, 2013 at 21:05
  • You need to restart the server in order for the new max to take effect outside the context of your own connection. Thus, you specify the max var in the settings file. Nov 14, 2013 at 21:09
  • 1
    I will try it and inform you what happens, thanks.
    – antf
    Nov 14, 2013 at 21:11
  • Note that max_connections is at default to 200 for a reason, and setting 1.000.000 is probably nonsense for your hardware resources. Also, probably the problem is not related to this fix. Try inspecting your SHOW FULL PROCESSLIST to understand what is happening and if there are really few connections available or if it's something else. Please add these info in your question. Feb 10 at 17:14

3 Answers 3

82

How to change max_connections

You can change max_connections while MySQL is running via SET:

mysql> SET GLOBAL max_connections = 5000;
Query OK, 0 rows affected (0.00 sec)

mysql> SHOW VARIABLES LIKE "max_connections";
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections | 5000  |
+-----------------+-------+
1 row in set (0.00 sec)

To OP

timeout related

I had never seen your error message before, so I googled. probably, you are using Connector/Net. Connector/Net Manual says there is max connection pool size. (default is 100) see table 22.21.

I suggest that you increase this value to 100k or disable connection pooling Pooling=false

UPDATED

he has two questions.

Q1 - what happens if I disable pooling Slow down making DB connection. connection pooling is a mechanism that use already made DB connection. cost of Making new connection is high. http://en.wikipedia.org/wiki/Connection_pool

Q2 - Can the value of pooling be increased or the maximum is 100?

you can increase but I'm sure what is MAX value, maybe max_connections in my.cnf

My suggestion is that do not turn off Pooling, increase value by 100 until there is no connection error.

If you have Stress Test tool like JMeter you can test youself.

3
  • Thanks Jungsu, my problem is in pooling not in max_connections. I have 2 small questions here: what happens if I disable pooling, can I still support multiple connections? Can the value of pooling be increased or the maximum is 100? I understood from the link you provided that its maximum is 100, am I right?
    – antf
    Nov 21, 2013 at 19:38
  • @antf I have updated my answer. are you still getting a connection error?
    – Jason Heo
    Nov 22, 2013 at 0:30
  • When I run SET GLOBAL max_connections = 5000; inside PhpMyAdmin I get: "Access denied; you need (at least one of) the SUPER or SYSTEM_VARIABLES_ADMIN privilege(s) for this operation". In other words: You need to SSH into your server and then execute mysql and afterwards SET GLOBAL max_connections = 5000;
    – Avatar
    Apr 27 at 9:46
1

For Windows,

  1. Go to c:\xampp\mysql\bin\my.init
  2. Add max_connections = <your value> example max_connections = 5000

For Ubunutu:

  1. Go to sudo /opt/lampp/etc/my.cnf/
  2. Add max_connections = your value example max_connections = 5000
  3. sudo systemctl reload-deamon
0

You can set max connections using:

set global max_connections = '1 < your number > 100000';

This will set your number of mysql connection unti (Requires SUPER privileges).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.