diff --git a/requirements.txt b/requirements.txt index 1a8539d..d1deb45 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 diff --git a/services/common/config.py b/services/common/config.py index 6dc19e6..8e59c3f 100644 --- a/services/common/config.py +++ b/services/common/config.py @@ -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") diff --git a/services/common/database.py b/services/common/database.py index 156644f..46da1af 100644 --- a/services/common/database.py +++ b/services/common/database.py @@ -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,