linux查看mysql最大连接数_Linux MySQL连接数的查看和最大连接数的调整

Linux MySQL连接数的查看和最大连接数的调整

MariaDB [(none)]> show variables like '%open%';#当前mysql数据库可以打开的文件数目,打开一个表的动作就是打开一个文件哦,当然,和连接数也有关系,总之,只要有文件读写都算一次的。现在的值为1024

+-------------------+-------+

| Variable_name     | Value |

+-------------------+-------+

| have_openssl      | YES   |

| innodb_open_files | 431   |

| open_files_limit  | 1024  |

| table_open_cache  | 431   |

+-------------------+-------+

4 rows in set (0.01 sec)

MariaDB [(none)]> show variables like '%max_connections%';#最大连接数,也就是目前数据库所允许的最多的连接数是151

+-----------------------+-------+

| Variable_name         | Value |

+-----------------------+-------+

| extra_max_connections | 1     |

| max_connections       | 151   |

+-----------------------+-------+

2 rows in set (0.01 sec)

MariaDB [(none)]> show status like '%Threads_connected%';#实时的数据库现在的有效连接数,现在值为1

+-------------------+-------+

| Variable_name     | Value |

+-------------------+-------+

| Threads_connected | 1     |

+-------------------+-------+

1 row in set (0.00 sec)

MariaDB [(none)]> show status like '%Threads_create%';#数据库新建的连接数,现在值为4

+-----------------+-------+

| Variable_name   | Value |

+-----------------+-------+

| Threads_created | 4     |

+-----------------+-------+

1 row in set (0.00 sec)

执行ulimite -a 命令,结果如下(open files  (-n) 1024):

[root@centos7 ~]# ulimit -a

core file size          (blocks, -c) 0

data seg size           (kbytes, -d) unlimited

scheduling priority             (-e) 0

file size               (blocks, -f) unlimited

pending signals                 (-i) 15718

max locked memory       (kbytes, -l) 64

max memory size         (kbytes, -m) unlimited

open files                      (-n) 1024

pipe size            (512 bytes, -p) 8

POSIX message queues     (bytes, -q) 819200

real-time priority              (-r) 0

stack size              (kbytes, -s) 8192

cpu time               (seconds, -t) unlimited

max user processes              (-u) 15718

virtual memory          (kbytes, -v) unlimited

file locks                      (-x) unlimited

如果数据库使用的并不多,也就是业务并不繁忙,那么可能以上数值都够用的,如果高并发,大流量的情况,很显然,数据库会吃不消报警的。如何解决?更改数据库的设定,使得它可以打开更多的表,保持更多的连接即可。

第一步:调整内核,使得用户层面的打开文件数提高

/etc/security/limits.conf  #该文件末尾添加如下内容:

* soft nofile 65535

* hard nofile 65535

* soft nproc 65535

* soft nproc 65535

第二步:vim /usr/lib/systemd/system/mariadb.service#只要是服务启动脚本就行了。

【server】下添加:

LimitNOFILE=65535#注意,这个是区分大小写的,不可大意。

LimitNPROC=65535

第三步:修改MySQL主配置文件my.cnf ,重新加载配置文件,重启服务

vim /etc/my.cnf

在mysqld字段内添加

max_connections=65535

保存文件,退出,执行命令 :systemctl daemon-reload && systemctl restart mariadb

第四步:验证结果

MariaDB [(none)]> show global variables like '%max_connec%';

+-----------------------+-------+

| Variable_name         | Value |

+-----------------------+-------+

| extra_max_connections | 1     |

| max_connect_errors    | 100   |

| max_connections       | 64725 |

+-----------------------+-------+

3 rows in set (0.00 sec)

MariaDB [(none)]> show global variables like '%open%';

+-------------------+-------+

| Variable_name     | Value |

+-------------------+-------+

| have_openssl      | YES   |

| innodb_open_files | 400   |

| open_files_limit  | 65535 |

| table_open_cache  | 400   |

+-------------------+-------+

4 rows in set (0.00 sec)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值