sort_buffer_size can reduce query performance, increase overall memory consumption, and even crash your cluster. This process is highly specific to your workload and we do not recommend changing the default value. Please read its potential use cases and disclaimers before changing it.
How do I fix the "Out of sort memory" error?
Validated on 20 Nov 2024 • Last edited on 18 Mar 2026
ERROR 1038 (HY001): Out of sort memory, consider increasing server sort buffer size
Sort Buffer Size (sort_buffer_size) is a MySQL server system variable that can affect your query performance. It is defined on a per-session level, impacting your cluster’s memory consumption.
To fix this error, increase sort_buffer_size to a value higher than its default of 256 KB. Having sort_buffer_size over 5 MB may significantly slow down memory allocation. To learn how to safely adjust sort_buffer_size, see our guide.
Related Topics
Update backup user permissions, remove the –single-transaction flag, or downgrade mysqldump.
Use MySQL’s import command instead of source for handling large data imports.
Remove or replace the DEFINER in the dump file.