connect_timeout
Seconds the server waits for a client to answer the handshake.
- Predeterminado
10- Range
- 2 to 31536000 seconds
- Restart needed
- No
- Default checked on
- MySQL 8.4 LTS
Lo que hace
mysqld waits this long for the client's connect packet after the TCP connection is accepted, then gives up with Bad handshake. Raising it helps clients that keep failing with 'Lost connection to MySQL server at waiting for initial communication packet', typically over slow or congested links.
Valor predeterminado
10. 10 seconds (MySQL 8.4).
Check the current value
SHOW GLOBAL VARIABLES LIKE 'connect_timeout'; SELECT VARIABLE_NAME, VARIABLE_SOURCE, MIN_VALUE, MAX_VALUE, SET_TIME FROM performance_schema.variables_info WHERE VARIABLE_NAME = 'connect_timeout';
Change it
SET GLOBAL connect_timeout = 30; -- until the next restart SET PERSIST connect_timeout = 30; -- now and after restarts
No restart. SET GLOBAL or SET PERSIST takes effect immediately; SET PERSIST also writes mysqld-auto.cnf so the value survives restarts.
When to change it
When legitimate clients fail to get through the handshake on slow links, or while investigating a rise in Aborted_connects in SHOW GLOBAL STATUS.
What can go wrong
Half-open handshakes each hold a thread until the timeout fires, so a large value lets a broken network or an aggressive connection flood tie up threads for minutes. The default ten seconds already covers most real links; fix the network before raising it much.
Questions about connect_timeout
What is the default value of connect_timeout in MySQL?
10. 10 seconds (MySQL 8.4).
Does changing connect_timeout require a restart?
No. No restart. SET GLOBAL or SET PERSIST takes effect immediately; SET PERSIST also writes mysqld-auto.cnf so the value survives restarts.
When should I change connect_timeout?
When legitimate clients fail to get through the handshake on slow links, or while investigating a rise in Aborted_connects in SHOW GLOBAL STATUS.
Back to all MySQL settings, or check the MySQL manual for every option.
Related on SQLly
Check connect_timeout on your own server
SQLly runs the query above against MySQL and the other engines in this reference, from one desktop app on macOS, Windows and Linux.
Texto y datos de esta página: CC BY 4.0, con atribución a SQLly (sqlly.app). Código y fragmentos SQL: MIT. Detalles de la licencia