修改Mariadb最大连接数


如何查看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
此方式在服务重启后失效。。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM