CentOS7.2 调整MariaDB数据库最大连接数


1. 查看mariadb数据库最大连接数,默认为151

mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 44070861
Server version: 5.5.52-MariaDB MariaDB Server

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show variables like 'max_connections';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections | 151   |
+-----------------+-------+
1 row in set (0.00 sec)

2. 配置/etc/my.cnf

[mysqld]新添加一行如下参数:

max_connections=1000

重启mariadb服务,再次查看mariadb数据库最大连接数,可以看到最大连接数是214,并非我们设置的1000。

vim /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
max_connections=1000

[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d


systemctl restart mariadb


MariaDB [(none)]>  show variables like 'max_connections';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections | 214   |
+-----------------+-------+
1 row in set (0.01 sec)

这是由于mariadb有默认打开文件数限制。可以通过配置/usr/lib/systemd/system/mariadb.service来调大打开文件数目。

3. 配置/usr/lib/systemd/system/mariadb.service

[Service]新添加两行如下参数

LimitNOFILE=1000

LimitNPROC=1000

vim /usr/lib/systemd/system/mariadb.service 
 
[Service]
Type=simple
User=mysql
Group=mysql
LimitNOFILE=10000
LimitNPROC=10000

systemctl daemon-reload
systemctl restart mariadb

再次查看mariadb数据库最大连接数,可以看到最大连接数已经是1000

MariaDB [(none)]> show variables like 'max_connections';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections | 1000  |
+-----------------+-------+
1 row in set (0.00 sec)

声明:初心|版权所有,违者必究|如未注明,均为原创|本网站采用BY-NC-SA协议进行授权

转载:转载请注明原文链接 - CentOS7.2 调整MariaDB数据库最大连接数


愿你勿忘初心,并从一而终