1960
MariaDBERRORCriticalResource LimitHIGH confidence
Can't create more than max_prepared_stmt_count statements
Production Risk
High — new queries cannot be prepared; application will error.
What this means
The server has reached the maximum number of simultaneously open prepared statements, controlled by the max_prepared_stmt_count system variable (default 16382).
Why it happens
- 1Application prepares statements without closing/deallocating them, causing a leak.
- 2Very high concurrency with each session keeping many prepared statements open.
- 3max_prepared_stmt_count set too low for the application workload.
How to reproduce
trigger — this will error
trigger — this will error
PREPARE stmt FROM 'SELECT 1'; -- fails when limit is reached
expected output
ERROR 1960 (42000): Can't create more than max_prepared_stmt_count statements (current value: 16382).
Fix 1
Deallocate prepared statements when no longer needed
Deallocate prepared statements when no longer needed
DEALLOCATE PREPARE stmt;
Why this works
Releasing prepared statements frees server resources and keeps the count below the limit.
Fix 2
Increase max_prepared_stmt_count if the limit is too low
Increase max_prepared_stmt_count if the limit is too low
SET GLOBAL max_prepared_stmt_count = 32768;
Why this works
Raising the limit allows more simultaneous prepared statements; monitor memory usage.
What not to do
✕
Sources
Official documentation ↗
MySQL 8.0 — 1960 ER_MAX_PREPARED_STMT_COUNT_REACHED
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev