【问题标题】:How to increase MySQL connections(max_connections)?如何增加 MySQL 连接数(max_connections)?
【发布时间】:2014-03-10 10:32:43
【问题描述】:

MySQL 数据库的每个套接字的默认连接数为 100,但我正在寻找任何方法来增加 MySQL 数据库的套接字连接的可能连接数 > 100。

【问题讨论】:

    标签: mysql database sockets database-connection


    【解决方案1】:

    如果您需要在不重启 MySQL 的情况下增加 MySQL 连接数,请执行以下操作

    mysql> show variables like 'max_connections';
    +-----------------+-------+
    | Variable_name   | Value |
    +-----------------+-------+
    | max_connections | 100   |
    +-----------------+-------+
    1 row in set (0.00 sec)
    
    mysql> SET GLOBAL max_connections = 150;
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> show variables like 'max_connections';
    +-----------------+-------+
    | Variable_name   | Value |
    +-----------------+-------+
    | max_connections | 150   |
    +-----------------+-------+
    1 row in set (0.00 sec)
    

    这些设置将在 MySQL 重新启动时更改。


    对于永久更改,在 my.cnf 中添加以下行并重新启动 MySQL

    max_connections = 150
    

    【讨论】:

    • 谢谢,但我可以知道最大限制吗?
    • 上限是什么意思?
    • @shekhar:- 最大并发连接可以是最大范围:4,294,967,295。检查这个:- dev.mysql.com/doc/refman/5.0/en/…
    • @AbdulManaf 非常感谢。所以你确定我们不需要重启 MySQL DB 吗?
    • @AbdulManaf 如果 MySQL 有更多的实例在运行,你可以帮助我,我必须如何移动才能实现这一目标?
    【解决方案2】:

    来自Increase MySQL connection limit:-

    MySQL 的默认配置将最大同时连接数设置为 100。如果您需要增加它,您可以相当轻松地做到这一点:

    对于 MySQL 3.x:

    # vi /etc/my.cnf
    set-variable = max_connections = 250
    

    对于 MySQL 4.x 和 5.x:

    # vi /etc/my.cnf
    max_connections = 250
    

    完成更改后重新启动 MySQL 并通过以下方式验证:

    echo "show variables like 'max_connections';" | mysql
    

    编辑:-(来自 cmets)

    最大并发连接数可以是最大范围:4,294,967,295。检查MYSQL docs

    【讨论】:

    • 谢谢,但最大连接数是多少?
    • @shekhar:- 更新了我的答案!
    • @shekhar:- 还要补充一点,如果您有任何机会达到该限制,您可能会耗尽内存。作为建议,您应该从简单开始,稍后根据需要添加复杂性。所以取一个较小的数字,比如 100 或者可能是 1000
    • @shekhar:- 是的,这是一个很好的做法,它还可以让您有效地反映更改!
    • @shekhar:- Before increasing MySQL’s connection limit, you really owe it to yourself (and your server), to find out why you’re reaching the maximum number of connections. Over 90% of the MySQL servers that are hitting the maximum connection limit have a performance limiting issue that needs to be corrected instead.
    【解决方案3】:

    我遇到了同样的问题,我用 MySQL 工作台解决了它,如所附屏幕截图所示:

    1. 在导航器(左侧)的“管理”部分下,点击“状态和系统变量”,
    2. 然后选择“系统变量”(顶部的选项卡),
    3. 然后在搜索栏搜索“连接”,
    4. 和 5. 您将看到两个字段需要调整以满足您的需求(max_connections 和 mysqlx_max_connections)。

    希望有帮助!

    The system does not allow me to upload pictures, instead please click on this link and you can see my screenshot...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-14
      • 1970-01-01
      • 1970-01-01
      • 2017-03-13
      • 2014-04-20
      相关资源
      最近更新 更多