MySQL Connections
Configuration
host_cache_size
Check
SELECT @@host_cache_size;
SHOW GLOBAL VARIABLES LIKE "host_cache_size";
Set
SET GLOBAL host_cache_size=200;
Requires the SYSTEM_VARIABLES_ADMIN privilegeFlushing the Host Cache
The cache can be flushed by changing the host_cache_size (see above), truncating the host_cache table, or executing the FLUSH HOSTS command.
TRUNCATE TABLE performance_schema.host_cache;
Requires the DROP privilige for the table.FLUSH HOSTS;
Requires the RELOAD privilegeDeprecated as of MySQL 8.0.23 (8)interactive_timeout
The number of seconds the server waits for activity on an interactive connection before closing it. (2)
Check
SELECT @@interactive_timeout;
SHOW GLOBAL VARIABLES LIKE "interactive_timeout";
Set
SET GLOBAL interactive_timeout=28800;
SET GLOBAL interactive_timeout=180;
SET GLOBAL interactive_timeout=3600;
# 8 Hours (Default)
# 3 Minutes
# 1 hour
max_connections
Defines the upper limit for the number of concurrent connections.
Check
SELECT @@max_connections;
SHOW GLOBAL VARIABLES LIKE "max_connections";
SELECT *
  FROM performance_schema.variables_info
 WHERE variable_name = 'max_connections';Â
SHOW STATUS LIKE 'MAX_USED_CONNECTIONS%';
Max_used_connections_time shows the time when the maximum number of concurrent connections since instance start (or status flush) was reached.
Set
SET GLOBAL max_connections = 150;
Changes setting only until instance restartSET PERSIST max_connections = 150;
Persists setting to mysqld-auto.cnf (which overrides my.cnf at restart)The maximum value is: 4294967295
max_connect_errors
SELECT @@max_connect_errors;
SHOW GLOBAL VARIABLES LIKE "max_connect_errors";
max_execution_time
Specifies how long (in milliseconds) a query can execute for before it is automatically killed.
Check
SELECT @@max_execution_time;
SHOW GLOBAL VARIABLES LIKE "max_execution_time";
Set
SET GLOBAL max_execution_time=0;
SET GLOBAL max_execution_time=1800000;
SET GLOBAL max_execution_time=2700000;
SET GLOBAL max_execution_time=3600000;
# Disable
# 30 minutes
# 45 minutes
# 1 hour
wait_timeout
The number of seconds the server waits for activity on a noninteractive connection before closing it. (1)
Check
SELECT @@wait_timeout;
SHOW GLOBAL VARIABLES LIKE "wait_timeout";
Set
SET GLOBAL wait_timeout=28800;
SET GLOBAL wait_timeout=180;
SET GLOBAL wait_timeout=3600;
# 8 Hours (Default)
# 3 Minutes
# 1 hour
Status Counters
Aborted_clients
"The number of connections that were aborted because the client died without closing the connection properly." (3)
Common Causes
Client not closing the connection properly
Aborted_connects
"The number of failed attempts to connect to the MySQL server." (4)
These should correlate to entires like this in the mysql.log (if log_warnings parameter is set to 2)...
2023-01-11T03:24:06.161568Z 3067 [Note] Aborted connection 3067 to db: 'mydb' user: 'mysuer' host: 'myhost' (Got timeout reading communication packets)Common Causes
Incorrect password
No matching host for user
Malformed connection strings (e.g. port scanners can trigger this).
Hitting max_connections limit (see earlier on this page).
Killing connections
Connections
"The number of connection attempts (successful or not) to the MySQL server." (6)
Connection_errors_accept
"The number of errors that occurred during calls to accept() on the listening port." (5)
Connection_errors_internal
"The number of connections refused due to internal errors in the server, such as failure to start a new thread or an out-of-memory condition." (5)
Connection_errors_max_connections
"The number of connections refused because the server max_connections limit was reached." (5)
Connection_errors_peer_address
"The number of errors that occurred while searching for connecting client IP addresses." (5)
Connection_errors_select
"The number of errors that occurred during calls to select() or poll() on the listening port. (Failure of this operation does not necessarily means a client connection was rejected.)" (5)
Connection_errors_tcpwrap
"The number of connections refused by the libwrap library." (5)
Bibliography & References
COUNTERSAborted_clients(3) https://dev.mysql.com/doc/refman/5.6/en/server-status-variables.html#statvar_Aborted_clients
Aborted_connects(4) https://dev.mysql.com/doc/refman/5.6/en/server-status-variables.html#statvar_Aborted_connectshttps://dba.stackexchange.com/questions/154531/how-do-i-determine-the-cause-of-high-mysql-aborted-connects-counthttps://stackoverflow.com/questions/23689803/mysql-aborted-connections-how-to-track-down-cause
Connection_errors_xxx(5) https://dev.mysql.com/doc/refman/5.6/en/server-status-variables.html#statvar_Connection_errors_xxx
Connections(6) https://dev.mysql.com/doc/refman/5.6/en/server-status-variables.html#statvar_Connections
CONFIGURATIONhttps://dev.mysql.com/blog-archive/mysql-8-0-persisting-configuration-variables/
host_cache_size(7) https://dev.mysql.com/doc/refman/8.0/en/host-cache.html(8) https://dev.mysql.com/doc/refman/8.0/en/flush.html#flush-hosts
interactive_timeout(2) https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_interactive_timeouthttps://orbisius.com/blog/change-mysqls-wait_timeout-interactive_timeout-variables-p1699
max_connectionshttps://stackoverflow.com/questions/22297773/how-to-increase-mysql-connectionsmax-connectionshttps://stackoverflow.com/questions/16584061/mysql-max-user-connections-recommended-settingshttps://dba.stackexchange.com/questions/233886/configuring-the-max-connections-setting-in-mysql
max_used_connectionshttps://dev.mysql.com/doc/refman/8.4/en/server-status-variables.html#statvar_Max_used_connections
max_execution_timehttps://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_max_execution_time
wait_timeout(1) https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_wait_timeouthttps://orbisius.com/blog/change-mysqls-wait_timeout-interactive_timeout-variables-p1699https://serverfault.com/questions/355750/mysql-lowering-wait-timeout-value-to-lower-number-of-open-connectionshttps://dba.stackexchange.com/questions/189129/mysql-wait-timeout-variable