V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
MySQL 5.5 Community Server
MySQL 5.6 Community Server
Percona Configuration Wizard
XtraBackup 搭建主从复制
Great Sites on MySQL
Percona
MySQL Performance Blog
Severalnines
推荐管理工具
Sequel Pro
phpMyAdmin
推荐书目
MySQL Cookbook
MySQL 相关项目
MariaDB
Drizzle
参考文档
http://mysql-python.sourceforge.net/MySQLdb.html
Anivial
V2EX  ›  MySQL

Mysql max_connections 的合理配置是多少?

  •  
  •   Anivial · Jul 15, 2022 · 1718 views
    This topic created in 1384 days ago, the information mentioned may be changed or developed.

    由于最近会时不时遇到 too many connections 的情况

    有很多解决方案,比如:

    1. 调高 max_connections ,现在是 400
    2. 连接池
    3. 分散数据库连接(数据库集群)
    4. 业务逻辑判断,耗时任务预先关闭数据库连接

    由于时间问题,并且池化也会导致溢出连接会变为阻塞,暂时准备先用 1 方案开始解决,但是网上对于 max_connections 设定多少很难找到标准 mysql 中的标准是 Max_used_connections / max_connections * 100% ≈ 85% Max_used_connections 会由于 max_connections 设置 400 只记录了 401 ,实际应该是超过这个值

    所以希望有经验的大佬能提供下合理的配置参数,mysql 所在服务器是 2 核 4G

    万分感谢

    4 replies    2022-07-15 16:57:37 +08:00
    GlobalNPC
        1
    GlobalNPC  
       Jul 15, 2022
    先分析一下是哪些应用占用的? 看一下是不是合理
    Anivial
        2
    Anivial  
    OP
       Jul 15, 2022
    @infun 在占用过多的时候检查过,主要是一个应用的连接会由于使用者在该时间段会过多,导致的连接激增
    helone
        3
    helone  
       Jul 15, 2022
    我觉得还是上连接池吧
    F281M6Dh8DXpD1g2
        4
    F281M6Dh8DXpD1g2  
       Jul 15, 2022
    连接池
    你有多少核心就设置多大
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5479 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 03:16 · PVG 11:16 · LAX 20:16 · JFK 23:16
    ♥ Do have faith in what you're doing.