openstack中数据库连接数太多--pymysql.err.OperationalError,1040, u'Too many connections'

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
云数据库 RDS PostgreSQL,集群系列 2核4GB
简介: 1.出现问题: openstack运行过程中出现如下问题: OperationalError: (pymysql.err.OperationalError) (1040, u'Too many connections') DBConnectionError: (pymysql.

1.出现问题:

openstack运行过程中出现如下问题:

OperationalError: (pymysql.err.OperationalError) (1040, u'Too many connections')

DBConnectionError: (pymysql.err.OperationalError) (2003, "Can't connect to MySQL server on 'controller' ([Errno 111] ECONNREFUSED)") [SQL: u'SELECT 1']

2.查看 mysql 状态

 2.1查看 mysql 的最大连接数

mysql> show variables like 'max_connections';
+-----------------+-------+
| Variable_name  | Value  |
+-----------------+-------+
| max_connections | 214   |
+-----------------+-------+
1 row in set (0.00 sec)

2.2 查看服务器响应的最大连接数

mysql> show global status like 'Max_used_connections';
+----------------------+-------+
| Variable_name    | Value     |
+----------------------+-------+
| Max_used_connections | 215   |
+----------------------+-------+
1 row in set (0.00 sec)

对于 mysql 服务器最大连接数值的设置范围比较理想的是:服务器响应的最大连接数值占服务器上限连接数值的比例值在 10% 以上,如果在 10% 以下,说明 mysql 服务器最大连接上限值设置过高。

Max_used_connections / max_connections * 100%

 

这的服务器响应的最大连接数已经达到了 mysql 的最大连接数的最大值

3.问题分析

3.1 max_connections

MySQL无论如何都会保留一个用于管理员(SUPER)登陆的连接,用于管理员连接数据库进行维护操作,即使当前连接数已经达到了max_connections。因此MySQL的实际最大可连接数为 max_connections+1

这个参数实际起作用的最大值(实际最大可连接数)为16384,即该参数最大值不能超过16384,即使超过也以16384为准; 增加max_connections参数的值,不会占用太多系统资源。系统资源(CPU、内存)的占用主要取决于查询的密度、效率等; 该参数设置过小的最明显特征是出现”Too many connections”错误;

3.2 mysql 最大连接数 214 问题

如果我设置连接小于214时,比如 200,那么实际连接数就是 200,也就是说,我的配置文件是没有问题的。

查 MySQL 官方文档,里面说了

The maximum number of connections MySQL can support depends on the quality of the thread library on a given platform, the amount of RAM available, how much RAM is used for each connection, the workload from each connection, and the desired response time. Linux or Solaris should be able to support at 500 to 1000 simultaneous connections routinely and as many as 10,000 connections if you have many gigabytes of RAM available and the workload from each is low or the response time target undemanding. Windows is limited to (open tables × 2 + open connections) < 2048 due to the Posix compatibility layer used on that platform.

Increasing open-files-limit may be necessary. Also see Section 2.5, “Installing MySQL on Linux”, for how to raise the operating system limit on how many handles can be used by MySQL.

大概意思是 MySQL 能够支持的最大连接数量受限于操作系统,必要时可以增大 open-files-limit。换言之,连接数与文件打开数有关。

4 问题解决

更改 MySQL 在 Linux 的最大文件描述符限制,编辑/usr/lib/systemd/system/mariadb.service文件,在文件[Service]下添加:

LimitNOFILE=65535
LimitNPROC=65535

 

保存后,执行下面命令,使配置生效

# systemctl daemon-reload
# systemctl restart  mariadb.service

 

问题解决

MariaDB [(none)]> show variables like 'max_connections';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections | 4096  |
+-----------------+-------+
相关实践学习
如何快速连接云数据库RDS MySQL
本场景介绍如何通过阿里云数据管理服务DMS快速连接云数据库RDS MySQL,然后进行数据表的CRUD操作。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
11月前
|
关系型数据库 MySQL 数据库连接
用Navicat备份Mysql演示系统数据库的时候出:Too Many Connections
用Navicat备份Mysql演示系统数据库的时候出:Too Many Connections
450 0
|
Linux Apache Python
【openstack排坑指南】 “too many open files” Linux系统文件句柄优化
【openstack排坑指南】 “too many open files” Linux系统文件句柄优化
292 0
|
消息中间件 存储 缓存
(二)OpenStack---M版---双节点搭建---数据库安装和配置
(二)OpenStack---M版---双节点搭建---数据库安装和配置
305 0
(二)OpenStack---M版---双节点搭建---数据库安装和配置
|
SQL Java 关系型数据库
数据库连接问题之:Caused by: java.sql.SQLException: Connections could not be acquired from the underlying database!
要么是驱动问题(没加载到工程中去或者其他问题)要么是账号密码或者url或者driver写错 driver:com.mysql.jdbc.Driver url:jdbc:mysql://localhost:3306/数据库名称
5357 0
|
1月前
|
关系型数据库 MySQL Java
【YashanDB知识库】原生mysql驱动配置连接崖山数据库
【YashanDB知识库】原生mysql驱动配置连接崖山数据库
【YashanDB知识库】原生mysql驱动配置连接崖山数据库
|
1月前
|
关系型数据库 MySQL 数据库连接
docker拉取MySQL后数据库连接失败解决方案
通过以上方法,可以解决Docker中拉取MySQL镜像后数据库连接失败的常见问题。关键步骤包括确保容器正确启动、配置正确的环境变量、合理设置网络和权限,以及检查主机防火墙设置等。通过逐步排查,可以快速定位并解决连接问题,确保MySQL服务的正常使用。
341 82
|
4天前
|
负载均衡 算法 关系型数据库
大数据新视界--大数据大厂之MySQL数据库课程设计:MySQL集群架构负载均衡故障排除与解决方案
本文深入探讨 MySQL 集群架构负载均衡的常见故障及排除方法。涵盖请求分配不均、节点无法响应、负载均衡器故障等现象,介绍多种负载均衡算法及故障排除步骤,包括检查负载均衡器状态、调整算法、诊断修复节点故障等。还阐述了预防措施与确保系统稳定性的方法,如定期监控维护、备份恢复策略、团队协作与知识管理等。为确保 MySQL 数据库系统高可用性提供全面指导。
下一篇
oss创建bucket