// mysql · connections

thread_cache_size

Threads kept for reuse after a client disconnects.

Standard
9 (autosized)
Range
0 to 16384
Restart needed
Nein
Default checked on
MySQL 8.4 LTS

Was es bewirkt

Reusing a thread avoids creating one for each new connection. -1 at startup means autosize: 8 + max_connections / 100.

Standardwert

9 (autosized). Autosized to 8 + max_connections / 100, which is 9 with the default 151 (MySQL 8.4).

Check the current value

SHOW GLOBAL VARIABLES LIKE 'thread_cache_size';

SELECT VARIABLE_NAME, VARIABLE_SOURCE, MIN_VALUE, MAX_VALUE, SET_TIME
FROM performance_schema.variables_info
WHERE VARIABLE_NAME = 'thread_cache_size';

Change it

SET GLOBAL thread_cache_size = 64;    -- until the next restart
SET PERSIST thread_cache_size = 64;   -- 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 Threads_created keeps climbing relative to Connections on a server with many short connections.

What can go wrong

Very low risk; cached threads use a little memory.

Questions about thread_cache_size

What is the default value of thread_cache_size in MySQL?

9 (autosized). Autosized to 8 + max_connections / 100, which is 9 with the default 151 (MySQL 8.4).

Does changing thread_cache_size 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 thread_cache_size?

When Threads_created keeps climbing relative to Connections on a server with many short connections.

Back to all MySQL settings, or check the MySQL manual for every option.

// one client for every engine

Check thread_cache_size 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.