MySQL reconnection mechanism optimization

This commit is contained in:
Liujian committed 2026-02-03 10:00:02 +08:00
1 parent 33d66e7d3b
commit fab064975d
3 files changed
+4 -3

No files matched your search

+1 -1
View File
@@ -5,7 +5,7 @@ pydantic>=2.8.2
python-dotenv>=1.0.1
redis>=5.0.8
pika>=1.3.2
mysql-connector-python>=9.0.0
pymysql>=1.1.0
objtyping
stripe>=5.0.0
aiohttp>=3.8.0
+2 -1
View File
@@ -25,7 +25,8 @@ class Config:
DB_POOL_SIZE = int(os.getenv("DB_POOL_SIZE", 20))
DB_MAX_OVERFLOW = int(os.getenv("DB_MAX_OVERFLOW", 30))
DB_POOL_TIMEOUT = int(os.getenv("DB_POOL_TIMEOUT", 30))
DB_POOL_RECYCLE = int(os.getenv("DB_POOL_RECYCLE", 3600))
# 默认回收时间改为600秒(10分钟),避免防火墙或MySQL wait_timeout断开连接
DB_POOL_RECYCLE = int(os.getenv("DB_POOL_RECYCLE", 600))
DB_POOL_PRE_PING = os.getenv("DB_POOL_PRE_PING", "true").lower() == "true"
SMTP_HOST = os.getenv("SMTP_HOST", "smtp.example.com")
+1 -1
View File
@@ -8,7 +8,7 @@ logger = logging.getLogger(__name__)
# Build database engine configuration
engine_config = {
"url": f"mysql+mysqlconnector://{Config.MYSQL_USER}:{Config.MYSQL_PASSWORD}@{Config.MYSQL_HOST}:{Config.MYSQL_PORT}/{Config.MYSQL_DB}",
"url": f"mysql+pymysql://{Config.MYSQL_USER}:{Config.MYSQL_PASSWORD}@{Config.MYSQL_HOST}:{Config.MYSQL_PORT}/{Config.MYSQL_DB}",
"echo": Config.DEBUG,
"pool_size": Config.DB_POOL_SIZE,
"max_overflow": Config.DB_MAX_OVERFLOW,