如何查看Mariadb最大連接數?
1.登錄Mariadb數據庫
[root@controller ~]# mysql -uroot -p123456
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 48
Server version: 10.1.20-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)]>
2.命令查詢最大連接數
MariaDB [(none)]> show variables like '%max_connections%';
+-----------------------+-------+
| Variable_name | Value |
+-----------------------+-------+
| extra_max_connections | 1 |
| max_connections | 190 |
+-----------------------+-------+
如何修改Mariadb最大連接數?
1.Mariadb的配置文件默認目錄在/etc下,修改/etc/my.cnf文件。在[mysqld]下新增如下配置:
max_connections=1000
2.重啟Mariadb服務
systemctl restart mariadb.service
3.查看最大連接數是否修改
MariaDB [(none)]> show variables like 'max_connections';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 214 |
+-----------------+-------+
1 row in set (0.00 sec)
發現最大連接數改為214並不是我們設置的1000。。。這是因為Mariadb有默認的打開文件數限制。
4.配置Mariadb打開文件數,修改/usr/lib/systemd/system/mariadb.service文件,在[Service]下新增如下配置:
LimitNOFILE=10000
LimitNPROC=10000
5.重新加載系統服務並重啟Mariadb服務
systemctl --system daemon-reload
systemctl restart mariadb.service
6.再次查看Mariadb最大連接數
MariaDB [(none)]> show variables like 'max_connections';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 4096 |
+-----------------+-------+
1 row in set (0.00 sec)
發現雖然連接數變大了,但是依然不是我們配置的1000。。。這是因為環境中Mariadb啟動時使用的是Openstack的數據庫配置文件。
7.配置Openstack數據庫配置文件,修改/etc/my.cnf.d/server.cnf文件。在[mysqld]下新增如下配置:
max_connections=1000
8.重啟Mariadb服務
systemctl restart mariadb.service
9.再次查看Mariadb最大連接數
MariaDB [(none)]> show variables like 'max_connections';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 1000 |
+-----------------+-------+
1 row in set (0.01 sec)
終於成功啦~~~~~
PS: 臨時處理方式,直接用命令在數據庫中修改。
set GLOBAL max_connections=1000
此方式在服務重啟后失效。。