zoukankan      html  css  js  c++  java
  • MySQL参数最大连接数max_connections

    1、查看最大连接数

     mysql> show status like 'Threads%';
    +-------------------+-------+
    | Variable_name     | Value |
    +-------------------+-------+
    | Threads_cached    | 58    |
    | Threads_connected | 57    |   ###这个数值指的是打开的连接数
    | Threads_created   | 3676  |
    | Threads_running   | 4     |   ###这个数值指的是激活的连接数,这个数值一般远低于connected数值
    +-------------------+-------+
     
    Threads_connected 跟show processlist结果相同,表示当前连接数。准确的来说,Threads_running是代表当前并发数
     
    这是是查询数据库当前设置的最大连接数
    mysql> show variables like '%max_connections%';
    +-----------------+-------+
    | Variable_name   | Value |
    +-----------------+-------+
    | max_connections | 1000  |
    +-----------------+-------+
     
    可以在/etc/my.cnf里面设置数据库的最大连接数
    [mysqld]
    max_connections = 1000

    2、show status

       Threads_connected  当前的连接数
       Connections  试图连接到(不管是否成功)MySQL服务器的连接数。
       Max_used_connections  服务器启动后已经同时使用的连接的最大数量。

    3、设置最大连接数


    set GLOBAL max_connections=2000; set GLOBAL max_user_connections=1500; mysql> show global variables like "max%connections"; +----------------------+-------+ | Variable_name | Value | +----------------------+-------+ | max_connections | 2000 | | max_user_connections | 1500 | +----------------------+-------+ 2 rows in set (0.08 sec)

    说明,

    系统支持的最大连接max_connections

    用户能最大连接进来的数量max_user_connections

    别忘记在配置文件里添加否则重启失效

    max_connections=1000;

    max_user_connection=600

    以上设置,为自己和其他用户预留几个连接空闲

    4、修改/etc/my.cnf中的max_connections


    5、show processlist   显示当前正在执行的MySQL连接

    6、mysqladmin -u<user> -p<pwd> -h<host> status

    显示当前MySQL状态
    
       Uptime: 13131  Threads: 1  Questions: 22  Slow queries: 0  Opens: 16  Flush tables: 1  Open tables: 1  Queries per second avg: 0.1
    
    
       mysqladmin -u<user> -p<pwd> -h<host> extended-status
    
       显示mysql的其他状态
    
    +-----------------------------------+----------+
    | Variable_name                     | Value    |
    +-----------------------------------+----------+
    | Aborted_clients                   | 0        |
    | Aborted_connects               | 1        |
    | Binlog_cache_disk_use       | 0        |
    | Binlog_cache_use               | 0        |
    | Bytes_received                   | 1152   |
    | Bytes_sent                         | 10400 |
    | Com_admin_commands      | 0        |
    | Com_assign_to_keycache  | 0        |
    
    .............................................................
    
    .............................................................
    
    | Threads_cached                 | 2        |
    | Threads_connected            | 1        |
    | Threads_created                | 3        |
    | Threads_running                | 1        |
    | Uptime                                | 13509    |
    | Uptime_since_flush_status | 13509    |
    +-----------------------------------+----------+

    7、遇到最大连接数处理

    [推荐] 使用 mysqladmin flush-hosts 命令清理一下hosts文件(不知道mysqladmin在哪个目录下可以使用命令查找:whereis mysqladmin);
    
    mysqladmin flush-hosts -h192.168.x.x -Pxxxx -uroot -pxxxx;

    8、OS ulimit参数

    [root@emsc ~]# ulimit -n
    65535

    参考

    MYSQL 最大连接数设置-毛虫小臭臭-51CTO博客 http://blog.51cto.com/moerjinrong/1969909

    Mysql 查看连接数,状态 最大并发数 - CSDN博客 https://blog.csdn.net/makang110/article/details/75226522

    mysql 最大链接数 max_connections 设置-12917979-51CTO博客 http://blog.51cto.com/12927979/2047537

  • 相关阅读:
    Spring (4)框架
    Spring (3)框架
    Spring (2)框架
    javaSE面试题总结 java面试题总结
    分层结构
    三次握手
    17_网络编程
    16_多线程
    Ecplise中指定tomcat里Web项目发布文件
    Web 项目没有发布到我们安装的tomcat目录下
  • 原文地址:https://www.cnblogs.com/paul8339/p/9081915.html
Copyright © 2011-2022 走看看