调整mysql数据库最大连接数

【查看mysql最大链接数】

MariaDB [(none)]> show variables like 'max_connections';

   

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

| Variable_name | Value |

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

| max_connections | 151 |

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

   

【配置/etc/my.cnf

[mysqld]新添加一行:

max_connections=1000

   

重启mariadb服务,再次查看最大连接数,发现是214,而不是我们设置的1000。

   

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

| Variable_name | Value |

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

| max_connections | 214 |

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

   

这是由于mariadb有默认打开文件数限制。

可以通过配置 /usr/lib/systemd/system/mariadb.service 来调大打开文件数目。

   

【配置 mariadb.service

   

[Service]新添加两行:

LimitNOFILE=10000

LimitNPROC=10000

   

【重新加载系统服务并重启】

systemctl --system daemon-reload

systemctl restart mariadb.service

   

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

| Variable_name | Value |

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

| max_connections | 1000 |

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

   

然后我们发现最大连接数已经发生了变化。

posted @ 2019-08-12 19:05  流年的夏天  阅读(1931)  评论(0编辑  收藏  举报