MariaDB max_connections Explained: Configuration, Limits, and Best Practices

Published: 2026-07-15

Introduction

The max_connections system variable specifies the maximum number of simultaneous client connections that a MariaDB server accepts.

Every application connecting to MariaDB—including PHP, Java, Python, Node.js, and other clients—consumes one connection. If all available connections are in use, additional clients cannot connect, and MariaDB returns a "Too many connections" error.

Configuring an appropriate connection limit is essential for maintaining a stable and responsive database server. Setting the value too low may prevent legitimate users from connecting, while setting it too high can increase memory consumption and reduce overall performance.

This guide explains how max_connections works, how to configure it, recommended values, and common configuration mistakes.

Test Environment

Operating System : AlmaLinux 10
PHP Version      : PHP 8.3
Web Server       : Nginx
PHP-FPM          : Enabled
Architecture     : x86_64
Last Tested      : July 2026

What Is max_connections?

The max_connections variable defines the maximum number of client connections MariaDB allows at the same time.

View the current value:

SHOW VARIABLES LIKE 'max_connections';

Example output:

+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections | 151   |
+-----------------+-------+

In this example, MariaDB accepts up to 151 concurrent client connections.

How It Works

Every client establishes its own database connection.

Application
      │
      ▼
MariaDB
      │
 ┌────┼────┐
 │    │    │
 ▼    ▼    ▼
Conn1 Conn2 Conn3
      ...
      │
Maximum Connections

When the connection limit is reached:

New Client
     │
     ▼
MariaDB
     │
     ▼
Too many connections

No new client can connect until an existing connection is released.

Check the Current Value

View the current configuration.

SHOW VARIABLES LIKE 'max_connections';

To check current usage:

SHOW STATUS LIKE 'Threads_connected';

Example:

Threads_connected = 38

This shows how many connections are currently active.

Change max_connections

Edit the MariaDB configuration file.

sudo nano /etc/my.cnf

Example:

[mysqld]

max_connections = 300

Save the file.

Restart MariaDB

Apply the new configuration.

sudo systemctl restart mariadb

Verify the service:

sudo systemctl status mariadb

Expected output:

Active: active (running)

Verify the New Value

After restarting:

SHOW VARIABLES LIKE 'max_connections';

Example:

max_connections = 300

Recommended Values

| Server Type      | Suggested Value |
| ---------------- | --------------- |
| Personal website |             100 |
| WordPress        |         150–300 |
| Small business   |             300 |
| Medium traffic   |             500 |
| High traffic     |           1000+ |

The optimal value depends on available memory, application design, and expected workload.

Memory Considerations

Each client connection consumes server resources.

Increasing max_connections from:

151

to

5000

does not automatically improve performance.

Instead, it may:

Increase memory usage.

Reduce overall efficiency.

Make the server unstable under heavy load.

Configure only as many connections as your server can realistically support.

Common Issues

Too Many Connections

Typical error:

ERROR 1040 (08004):

Too many connections

Possible causes:

Connection limit reached.

Applications not closing idle connections.

Long-running queries.

Connection pool misconfiguration.

Idle Connections

Applications sometimes leave unused connections open.

Check active processes:

SHOW PROCESSLIST;

Look for:

Sleeping connections.

Long-running queries.

Unexpected client sessions.

Setting max_connections Too High

Example:

max_connections = 10000

This may appear attractive, but every connection requires memory and other server resources.

A very high value can lead to excessive memory consumption and reduced stability.

Relationship with Other Variables

max_connections works together with several other MariaDB settings.

| Variable              | Purpose                            |
| --------------------- | ---------------------------------- |
| `wait_timeout`        | Closes idle connections            |
| `interactive_timeout` | Interactive session timeout        |
| `thread_cache_size`   | Reuses worker threads              |
| `max_allowed_packet`  | Maximum packet size per connection |

These settings should be tuned together rather than independently.

Best Practices

Set max_connections according to actual application requirements.

Monitor connection usage regularly.

Use connection pooling where supported.

Configure wait_timeout to release idle connections.

Investigate connection leaks before increasing the limit.

Monitor memory usage after changing connection limits.

Related Articles

MariaDB Explained

MariaDB wait_timeout Explained

MariaDB thread_cache_size Explained

MariaDB max_allowed_packet Explained

MariaDB innodb_buffer_pool_size Explained

Conclusion

The max_connections variable controls how many client connections a MariaDB server accepts simultaneously. Choosing an appropriate value helps maintain stable performance while preventing connection failures during periods of high demand.

Rather than simply increasing the limit, monitor actual connection usage, optimize application behavior, and tune related variables such as wait_timeout and thread_cache_size. A balanced configuration provides better scalability, lower memory usage, and a more reliable production database.

Explore More

Technology Guides →

MariaDB Explained: Essential Configuration Variables and Best Practices

MariaDB max_allowed_packet Explained: Configuration, Packet Size, and Best Practices

Nginx worker_connections Explained: Configuration, Limits, and Best Practices

Nginx client_max_body_size Explained: Configuration, Upload Limits, and Best Practices

Southeast Asia Insights →

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