I want to connect to my Amazon Aurora MySQL-Compatible Edition DB instance, but I receive a "Too many connections" error. I want to know the maximum connection value for my DB instance and how to change it.
Short description
When the number of client connections exceeds the max_connections parameter value in the DB instance, you receive the "Too many connections" error message.
To resolve this issue, first view all the queries and threads that are running on your DB instance. Then, activate logging on the DB instance. Review the existing connections, and end unnecessary connections to reduce connection pressure. Also, adjust your MySQL connection parameters. If you still experience the issue, then increase the maximum number of connections to your DB instance.
Resolution
View all the queries and threads that are running on your DB instance
View all the queries that are running on the DB instance. Then, check the Threads_Connected value to view the number of connections that are open. For more information, see Threads_connected on the MySQL website.
For MySQL 5.7, run the following command:
mysql> SELECT variable_value AS Threads_Connected FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE variable_name='threads_connected';
For MySQL 8.0, run the following command:
mysql> SELECT variable_value AS Threads_Connected from performance_schema.global_status where VARIABLE_NAME = 'threads_connected';
Note: Because Aurora can connect to the database from the rdsadmin administrative user, the value for threads_connected might be higher than max_connections.
It's a best practice to use threads_connected or information_schema.processlist instead of DatabaseConnections. The threads_connected and information_schema.processlist parameters show the available MySQL connections that other clients use.
DatabaseConnections shows the total remote TCP connections, not sleeping connections or sessions that the database engine creates for its own purposes. As a result, the DatabaseConnections value might be lower than the number of operations that the MySQL threads perform.
Activate logging on your DB instance
Activate logging on your Aurora MySQL-Compatible DB instance to identify the root cause of the increased number of connections. You can activate the general_log, slow_query_log, or Advanced Auditing log parameters.
End unnecessary connections on your DB instance
Use the rds_kill and rds_kill_query commands to end unnecessary user sessions and queries that are running on your DB instance.
Adjust your MySQL connection parameters
Adjust the following MySQL connection parameters for your DB instance based on your preferred values:
- wait_timeout
- interactive_timeout
- net_read_timeout
- net_write_timeout
- max_execution_time
- max_connect_errors
- max_user_connections
For more information about each of the preceding parameters, see Server system variables on the MySQL website.
Increase the maximum connections to your DB instance
If you still experience the issue after you adjust your connection parameters, then increase the maximum number of connections to your DB instance. To get the current max_connections value for your DB instance, check the parameter group that's attached to your DB instance. Or, run the following query:
select @@max_connections;
Aurora MySQL-Compatible and Amazon Relational Database Service (Amazon RDS) for MySQL DB instances have different amounts of memory overhead. The value of max_connections might be different for Aurora MySQL-Compatible and Amazon RDS for MySQL DB instances that use the same instance class.
To determine the maximum number of connections for your instance class, use the following formula:
max_connections = GREATEST({log(17179869184/805306368)*45},{log(17179869184/8187281408)*1000})
Note: The preceding example is for an Aurora MySQL-Compatible db.r8g.large instance with 16 GiB of memory. The DBInstanceClassMemory equals 17179869184 bytes. The current value for max_connections is 1000.
Example result:
max_connections = GREATEST(195.56,1000) = 1000
Note: The maximum number of connections for this db.r8g.large instance class with 16 GiB of memory equals the default value.
Increase the max_connections parameter
Note: It isn't a best practice to increase the max_connections value beyond the default value. Instead, scale your DB instance.
If you don't scale your DB instance and instead choose to increase the value of max_connections, then complete the following steps:
- Create a custom DB instance parameter group.
- Associate the parameter group with your DB instance.
- Increase the max_connections parameter value.
Note: An outage doesn't occur when you set a larger max_connections value.
Scale up your instance
If you exceed the maximum value for the max_connections parameter, then it's a best practice to scale your DB instance class. Your DB instance can experience an outage when it scales.
Use best practices to tune the max_connections parameter
If you changed the buffer pool and query cache settings for your DB cluster, then adjust the connection quota to consider the increase or decrease in available memory on the DB instances.
Set the max_connections parameter slightly higher than the maximum number of connections that you expect to open on each DB instance.
If you turned on Performance Insights, then Performance Schema is automatically activated. It's a best practice to use the default max_connections value when Performance Schema is activated. Performance Schema memory structures are automatically sized based on the server configuration.
Important: Performance Insights will reach its end of life on June 30, 2026. You can upgrade to the Advanced mode of Database insights before June 30, 2026. If you don't upgrade, then DB clusters that use Performance Insights will default to the Standard mode of Database Insights. Only the Advanced mode of Database Insights will support execution plans and on-demand analysis. If your clusters default to the Standard mode, then you might not be able to use these features on the console. To turn on the Advanced mode, see Turning on the Advanced mode of Database Insights for Amazon RDS and Turning on the Advanced mode of Database Insights for Amazon Aurora.
Use Amazon RDS proxy
If you still receive an error, then use Amazon RDS Proxy for Aurora to improve your application's ability to scale.
Related information
How do I resolve the "Got an error reading communication packets" error in Amazon RDS for MySQL or Aurora MySQL-Compatible?