MariaDB wait_timeout Explained: Idle Connections, Timeouts, and Best Practices
Introduction
The wait_timeout system variable specifies how long MariaDB keeps an idle non-interactive client connection open before automatically closing it.
When a client connects to MariaDB but remains inactive for longer than the configured timeout, the server releases the connection to free resources. Properly configuring wait_timeout helps prevent excessive idle connections while ensuring applications can maintain stable database communication.
This guide explains how wait_timeout works, how to configure it, recommended values, and common configuration mistakes.
Test Environment
What Is wait_timeout?
The wait_timeout variable defines how many seconds an idle non-interactive connection may remain open.
View the current value:
Example:
The value is measured in seconds.
In this example:
28800 seconds = 8 hours
If a connection remains idle for eight hours, MariaDB automatically closes it.
How It Works
The timer resets whenever the client sends another SQL statement.
Check the Current Value
You can also view both timeout settings:
Change wait_timeout
Edit the MariaDB configuration.
sudo nano /etc/my.cnf
Example:
[mysqld]
wait_timeout = 600
This sets the timeout to 10 minutes.
Save the file.
Restart MariaDB
Apply the configuration.
sudo systemctl restart mariadb
Verify:
sudo systemctl status mariadb
Expected output:
Active: active (running)
Verify the New Value
Recommended Values
The best value depends on your application's connection behavior.
Relationship with interactive_timeout
MariaDB maintains two similar timeout variables.
Most web applications use wait_timeout, while database administrators using the MariaDB console are more likely to be affected by interactive_timeout.
Common Issues
MySQL Server Has Gone Away
Typical error:
MySQL server has gone away
One possible cause is that the connection remained idle longer than the configured wait_timeout.
However, this error can also result from:
Oversized packets
Network interruptions
Server restarts
Client-side connection issues
Always investigate the underlying cause before changing timeout values.
Too Many Sleeping Connections
You can inspect current connections with:
SHOW PROCESSLIST;
Example:
Large numbers of sleeping connections may indicate:
Connection leaks
Poor connection management
Timeout values that are too high
Timeout Set Too Low
Example:
wait_timeout = 10
Applications with infrequent database activity may find their connections closed unexpectedly, requiring unnecessary reconnections.
Best Practices
Set wait_timeout according to your application's workload.
Monitor sleeping connections using SHOW PROCESSLIST.
Use connection pooling where available.
Close unused database connections in your application.
Avoid excessively long timeout values unless required.
Review timeout-related errors before increasing the setting.
Relationship with Other Variables
wait_timeout works together with several connection-related settings.
Tuning these variables together helps improve connection management and resource utilization.
Related Articles
MariaDB max_connections Explained
MariaDB connect_timeout Explained
MariaDB thread_cache_size Explained
MariaDB max_allowed_packet Explained
Conclusion
The wait_timeout variable determines how long MariaDB keeps idle non-interactive connections open before closing them automatically. Proper configuration helps release unused connections, conserve server resources, and improve overall database stability.
For most production environments, a timeout between 120 and 600 seconds provides a practical balance between efficient resource usage and application reliability. Rather than choosing the longest possible timeout, monitor actual connection behavior and adjust the setting to match your workload.
Explore More
› MariaDB connect_timeout Explained: Connection Timeouts and Best Practices
› MariaDB Explained: Essential Configuration Variables and Best Practices
› MariaDB max_connections Explained: Configuration, Limits, and Best Practices
› MariaDB innodb_buffer_pool_size Explained: Memory, Performance, and Best Practices
› Best Areas to Live in Bangkok in 2026: A Complete Guide for Expats and Digital Nomads
› Best Coworking Spaces in Bangkok 2026: A Guide for Digital Nomads and Remote Workers
› Why Do People in Southeast Asia Love Iced Drinks? The Climate, Culture, and Science Explained
› Best eSIM for Southeast Asia in 2026: Compare the Top Travel eSIMs