电脑疯子技术论坛|电脑极客社区

微信扫一扫 分享朋友圈

已有 1868 人浏览分享

mysql连接数设置操作(Toomanyconnections)教程

[复制链接]
1868 0


mysql在使用过程中,发现连接数超了~~~~

  1. [root@linux-node1 ~]# mysql -u glance -h 192.168.1.17 -p
  2. Enter password:
  3. ERROR 1040 (08004): Too many connections
复制代码


解决办法,这也是centos7下修改mysql连接数的做法:

1)临时修改

  1. MariaDB [(none)]> show variables like 'max_connections';
  2. +-----------------+-------+
  3. | Variable_name | Value |
  4. +-----------------+-------+
  5. | max_connections | 151 |
  6. +-----------------+-------+
复制代码


1 row in set (0.00 sec)

  1. MariaDB [(none)]> set GLOBAL max_connections=1000;
  2. Query OK, 0 rows affected (0.00 sec)
  3. MariaDB [(none)]> show variables like 'max_connections';
  4. +-----------------+-------+
  5. | Variable_name | Value |
  6. +-----------------+-------+
  7. | max_connections | 1000 |
  8. +-----------------+-------+
复制代码


1 row in set (0.00 sec)

2)永久修改:

配置/etc/my.cnf

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

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

  1. MariaDB [(none)]> show variables like 'max_connections';
  2. +-----------------+-------+
  3. | Variable_name | Value |
  4. +-----------------+-------+
  5. | max_connections | 214 |
  6. +-----------------+-------+
复制代码


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

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

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

LimitNOFILE=10000
LimitNPROC=10000


重新加载系统服务,并重启mariadb服务

  1. systemctl --system daemon-reload
  2. systemctl restart mariadb.service
复制代码


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

  1. MariaDB [(none)]> show variables like 'max_connections';
  2. +-----------------+-------+
  3. | Variable_name | Value |
  4. +-----------------+-------+
  5. | max_connections | 1000 |
  6. +-----------------+-------+
复制代码



您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

关注

0

粉丝

9021

主题
精彩推荐
热门资讯
网友晒图
图文推荐

Powered by Pcgho! X3.4

© 2008-2022 Pcgho Inc.