// MySQL error reference

MySQL error 4031: Disconnected by the server for inactivity

The connection sat idle longer than wait_timeout (or interactive_timeout) and the server closed it. Newer servers tell the client why.

Error number
4031
Name
ER_CLIENT_INTERACTION_TIMEOUT
SQLSTATE
HY000
Category
Connection and client
Error message
The client was disconnected by the server because of inactivity. See wait_timeout and interactive_timeout for configuring this behavior.

What it means

Since MySQL 8.0.24 the server sends this error to a client whose idle connection it is closing, instead of just dropping it. The client sees it on its next command. It's the same situation older versions report as 2006 (server has gone away).

Common causes

  • A connection left idle in a pool or a forgotten interactive session for longer than wait_timeout (8 hours by default).
  • A low wait_timeout set by a hosting provider.

How to fix it

  1. Configure the connection pool to retire or test idle connections before wait_timeout runs out.

  2. Raise the timeout if long idle periods are expected.

    SET PERSIST wait_timeout = 28800;

Related errors

More connection and client errors

The code and message text are from the MySQL 8.4 Error Message Reference. Browse the full MySQL error list or search every database error.

// fewer errors, faster fixes

Work on MySQL in SQLly

A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for MySQL and the other databases you use.