How to set max_connections in MySQL Programmatically

前端 未结 2 1888
一整个雨季
一整个雨季 2021-02-01 02:39

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 i

相关标签:
2条回答
  • 2021-02-01 03:04

    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.

    0 讨论(0)
  • 2021-02-01 03:05

    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).

    0 讨论(0)
提交回复
热议问题