1. 程式人生 > >CentOS7.4 修改mariadb數據庫最大連接數

CentOS7.4 修改mariadb數據庫最大連接數

mariadb數據庫最大連接數 mysql最大連接數 mysql數據庫最大連接數 數據庫最大連接數

為什麽修改這個?因為我zabbix-server日誌報錯,提示connection to database 'zabbix' failed: [1040] Too many connections錯誤,mariadb正常。想到應該是mysql最大連接數問題。

1、查看默認最大連接數,默認是151

[root@localhost zabbix]# /usr/bin/mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 14872
Server version: 5.5.56-MariaDB MariaDB Server
Copyright (c) 2000, 2017, 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]新添加一行:

[root@localhost zabbix]# vi /etc/my.cnf
max_connections=1000

重啟mariadb服務,並驗證最大連接數(沒顯示我們修改的):

[root@localhost zabbix]# systemctl restart mariadb.service
[root@localhost zabbix]# /usr/bin/mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 446
Server version: 5.5.56-MariaDB MariaDB Server
Copyright (c) 2000, 2017, 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 | 214   |
+-----------------+-------+
1 row in set (0.00 sec)


3、配置/usr/lib/systemd/system/mariadb.service來調大打開文件數目。

[root@localhost zabbix]# vi /usr/lib/systemd/system/mariadb.service
在[Service]新加這兩行:
LimitNOFILE=10000
LimitNPROC=10000


4、重新加載系統服務,並重啟mariadb服務

[root@localhost zabbix]# systemctl --system daemon-reload
[root@localhost zabbix]# systemctl restart mariadb.service


5、重新驗證下,是否為1000


MariaDB [(none)]> show variables like 'max_connections';
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id:    5
Current database: *** NONE ***
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections | 1000  |
+-----------------+-------+
1 row in set (0.00 sec)


CentOS7.4 修改mariadb數據庫最大連接數