centos 修改mysql的连接数_CentOS7.4 修改mariadb数据库最大连接数

为什么修改这个?因为我zabbix-server日志报错,提示connection to database 'zabbix' failed: [1040] Too many connections错误,mariadb正常。想到应该是mysql最大连接数问题。

实时查看mariadb数据库连接数命令(Threads):[root@localhost ~]# mysqladmin -uroot -p status

Enter password:

Uptime: 1888  Threads: 615  Questions: 211118  Slow queries: 1  Opens: 189  Flush tables: 2  Open tables: 215  Queries per second avg: 111.820

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、重新验证下,是否为1000MariaDB [(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)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值