tortoise / tortoise-orm

Familiar asyncio ORM for python, built with relations in mind
https://tortoise.github.io
Apache License 2.0
4.7k stars 390 forks source link

2013, 'Lost connection to MySQL server during query ([Errno 60] Operation timed out)' #1685

Open Caprey opened 4 months ago

Caprey commented 4 months ago

DATABASE_CONFIG

TORTOISE_ORM = {
    "connections": {
        "default": {
            "engine": "tortoise.backends.mysql", 
            "credentials": {
                "host": settings.mysql_host,    
                "port": settings.mysql_port,         
                "user": settings.mysql_user,         
                "password": settings.mysql_password,     
                "database": settings.mysql_database,
                "minsize": 1,           
                "maxsize": 5,           
                "charset": "utf8mb4",   
                "echo": True            
            }
        },
    },
    "apps": {
        "models": {
            "models": ["app.memoir.models", "app.diary.models", "app.chat.models", "aerich.models"],
            "default_connection": "default",
        }
    },
    "use_tz": False,
    "timezone": "Asia/Shanghai"
}
Abdeldjalil-H commented 4 months ago

This is most likely related to your database server configuration not tortoise. Can you check the value of wait_timeout using

SHOW VARIABLES LIKE 'wait_timeout';

If you have long queries that take longer than this value then you have to set your timeout to a bigger value.