max_connections选项不适用于mysqld

时间:2018-03-05 10:16:51

标签: mysql file connection-pooling

我在max_connections=2000设置/etc/my.conf并重新启动mysqld

但仍然max_connections apear卡在412

mysql>  SHOW VARIABLES LIKE "max_connections";
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections | 412  |
+-----------------+-------+
1 row in set (0.01 sec)

mysql>

我还尝试重新启动mysqld帖子

mysql> SET GLOBAL max_connections = 2000;

但在我仍然从查询max_connections | 412

获得SHOW VARIABLES LIKE "max_connections";

2 个答案:

答案 0 :(得分:1)

我通过更改打开文件数量的系统级限制来解决这个问题。

检查系统级别。运行命令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) 31168
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1012
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) 4096
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

open files限制必须超过max_connecitons

的值

要更改它,请执行以下操作

 sudo nano /etc/security/limits.conf

并添加/编辑

 *   hard    nofile  4096
 *   soft    nofile  4096

现在重新登录服务器并重新启动mysqld并检查

mysql>  SHOW VARIABLES LIKE "max_connections";
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections | 2000  |
+-----------------+-------+
1 row in set (0.01 sec)

mysql>

答案 1 :(得分:1)

  1. 为服务文件创建替代

    systemctl edit mysql.service

  2. 添加以下内容

    [Service]
    LimitNOFILE=4096
  1. 重新启动MySQL服务器

    service mysql restart