<p>The MySQL server aborted a thread because the operation exhausted its per-thread stack.</p>
<p>MySQL Error 1436: ER_STACK_OVERRUN_NEED_MORE means a query or procedure used more stack space than the thread_stack value allows, so MySQL stopped the thread to protect itself. Raise thread_stack in my.cnf and redesign deeply nested procedures to resolve the issue.</p>
Thread stack overrun: %ld bytes used of a %ld byte stack,
The error appears as: Thread stack overrun: X bytes used of a Y byte stack, and Z bytes needed. Use 'mysqld --thread_stack=#' to specify a bigger stack. It signals that the current connection consumed more memory than its reserved thread stack.
MySQL allocates a fixed stack for every client thread at startup. Stored procedures, functions, triggers, nested subqueries, and recursive Common Table Expressions consume that stack. When consumption exceeds the thread_stack size, the server halts the thread to avoid a crash and returns SQLSTATE HY000, error 1436.
The error commonly shows up during complex stored procedure calls, deeply nested loops, or recursion in MySQL 5.7 and MySQL 8.0. It can also surface when multiple BEFORE or AFTER triggers chain together on the same row event.
Because thread_stack defaults to 256KB on many Linux builds, modern workloads that involve large local variables or many call frames can exceed that limit quickly.
Unresolved, the overrun terminates the current session and rolls back the active transaction. In OLTP systems this leads to lost updates, application errors, and potential deadlocks. Increasing thread_stack or refactoring the code restores stability and throughput.
A CALL statement that invokes itself directly or indirectly keeps allocating stack frames until the limit is reached.
Multiple row-level triggers that chain updates or inserts can nest more than expected and exhaust the thread stack.
DECLARE statements that create big arrays or large VARCHAR variables live on the stack and quickly consume space.
Complex optimizer plans with many nested subqueries sometimes require additional stack for execution states.
A default or intentionally small thread_stack value magnifies the likelihood of hitting the limit.
Permission related, not stack related, but often seen during large migration scripts.
Indicates lock table memory exhaustion rather than thread stack exhaustion.
Long waits can occur after thread aborts caused by stack overruns.
Too many connections may appear if repeated stack overruns force clients to reconnect quickly.
No. thread_stack is a static global variable set at server startup, so any change requires a restart.
256K is default. Many production systems run 512K or 1M. Values above 2M rarely improve stability and waste memory.
Slightly higher memory usage per connection occurs, but CPU cost is negligible. Balance the value with expected concurrent sessions.
Galaxy's AI copilot reviews stored procedures, warns about deep recursion, and suggests iterative refactors, reducing the risk of stack overruns before code reaches production.