max_connections

Tuning max_connections variable
May 13, 2025 • Written by ROMAN AGABEKOV
This article is about the MySQL system variable max_connections. It explains the default value, how to check and modify it both temporarily and permanently, and the implications of changing this setting. The article highlights the importance of balancing the number of connections with available system memory since each connection consumes resources. It also describes common errors like "too many connections" when the limit is exceeded and advises on when and how to increase the limit safely.

Basic Details

The max_connections variable sets the maximum number of concurrent client connections.

Releem automatically tunes max_connections and 44 other variables to improve MySQL performance. Try Releem for Free, or deepen your understanding by reading our detailed article.

max_connections – Usage

Adjustment of the max_connections variable increases or decreases the max number of connections. Since MySQL 5.5, the default value of max_connections has been 151. This provides 150 client connections and 1 extra connection for administrator accounts with the coonection_admin privilege. This extra connection allows admin accounts the ability to connect for troubleshooting or other purposes when connections are maxed out.

The 'too many connections' error message indicates that all connections are in use and no new connections can be opened until an existing connection is closed.

max_connections – Configuration

max_connections system variable can be configured using the command line or configuration file:

Command Line:
mysqld> set global max_connections = XX

Replace XX with value to suit your database needs. This change will only be applied to new connections. Make a new connection to the server and the values will update. SET GLOBAL will not persist through a server restart.

Configuration File:
[mysqld]
max_connections = XX

Replace XX with value to suit your database needs. Must restart MySQL server to see changes applied. This change will be permanent until the max_connections value in the configuration file is changed again.

max_connections Considerations

In most cases, max_connections does not need to be increased. MySQL servers that are exceeding the default number of maximum connections typically have other performance issues that need correction.

In situations where increasing max_connections is appropriate, increasing max_connections by 100 connections at a time, until there is no longer a 'too many connections' error message.
When adjusting max_connections, it's important to consider the system's resources. What is the available RAM? What kinds of queries will the connections be using? This plays into how much RAM is used by each connection, as easy queries take significantly less RAM than other resource-intensive queries. Improperly setting max_connections too high will have detrimental impacts on RAM availability and query performance.

If Database Connection Utilization is more than 85% then you could increase max_connections.

Try to increase open_files_limit in case you can't increase max_connection variable.

max_connections related Health Checks

  1. Database Connection Utilization is an important metric that measures the percentage of maximum available database connections that are currently being used.
Don't worry about RAM or incrementally increasing max_connections until the 'too many connections' error is resolved. Releem handles all of the analysis, calculations, and considerations for you. Releem then recommends a new MySQL configuration and applies it automatically to improve your MySQL Performance Score.
FAQ:
MySQL max_connections Variable
What is max_connections in MySQL and what does it control?
It sets the maximum number of simultaneous client connections allowed to the MySQL server.

How can I check the current max_connections setting in MySQL?
Run: SHOW VARIABLES LIKE 'max_connections';

What causes the “Too many connections” error and how can I fix it?
This happens when active connections exceed the max_connections limit. Fix it by increasing the value or reducing unnecessary connections.

How can I change the max_connections value?
  • Temporarily via command line: SET GLOBAL max_connections = XX; (effective until server restart)
  • Permanently by setting max_connections = XX in the [mysqld] section of the configuration file and restarting the server.

What is the default max_connections value in MySQL versions 5.7 and 8.0?
Default is 151 connections.

What should I consider before increasing max_connections in MySQL?
Consider system RAM and query types, as more connections use more memory. Increasing it unnecessarily can degrade performance.

What is the difference between max_connections, max_user_connections, and max_used_connections?
• max_connections: total allowed connections
• max_user_connections: limit per user
• max_used_connections: peak number of used connections since server start

Can I change max_connections without restarting MySQL?
Yes, using SET GLOBAL, but the change won’t persist after restart unless updated in the config file.

When is it appropriate to increase max_connections?
If you frequently encounter "too many connections" errors or if your database connection utilization is above 85%.

How do I calculate a safe max_connections value for my server?
It depends on memory and workload. A good approach is to monitor memory usage and avoid running out of RAM due to excessive connections.

What are the recommended max_connections values for AWS RDS and other cloud platforms?
AWS RDS sets this based on instance size. You can’t freely modify it but can view it in the parameter group.

How does the max_connections setting impact MySQL memory usage and performance?
Each connection uses memory, so setting this too high can lead to excessive memory use and crashes if RAM is exhausted.

What tool can help optimize max_connections and other MySQL settings?
Releem is a tool that automatically detects performance issues, tunes variables including max_connections, and optimizes queries.
Releem automatically identifies MySQL performance issues, tunes configuration and optimizes SQL queries