Need help?

Our experts have had an average response time of 11.7 minutes in August 2021 to fix urgent issues.

We will keep your servers stable, secure, and fast at all times for one fixed price.

MySQL Error 1038 – Fix the Memory Allocation Error

by | Jul 6, 2021

Stuck with the MySQL Error 1038? We can help you.

When Mysql memory is insufficient to perform a query, we may come across this error.

As part of our Server Management Services, we assist our customers with several MySQL queries.

Today, let us see how our Support Techs fix the MySQL error for our customers.


MySQL Error 1038

Moving ahead, let us see the cause of this error and eventually the fix.

Most commonly, users may notice the error as shown below:

SQLSTATE[HY001]: Memory allocation error: 1038 Out of sort memory, consider increasing server sort buffer size.

This situation indicates that the Mysql memory is insufficient to perform a query.

For every session that is to perform, a sort allocates a buffer of this size.

The sort_buffer_size is not specific to any storage engine. In addition, it applies in a general manner for optimization.

At a minimum, this value must be large enough to accommodate fifteen tuples in the sort buffer.

Also, if we need to increase the value of max_sort_length we have to increase the value of sort_buffer_size.


How to fix this?

In order to fix this error, we can either optimize the query or increase the sort_buffer_size.

To increase the sort_buffer_size, we open the /etc.mysql/my.cnf and add the following lines:

sort_buffer_size = 256 k

After we modify the parameter, we restart the MySQL service:

systemctl restart mysqld

In addition, we raise it 4 M using the following command in MySQL:

mysql> SET GLOBAL sort_buffer_size = 1024 * 1024 * 4;

[Need help with the fix? We’d be happy to assist]



To conclude, we saw how our Support Techs fix the MySQL error for our customers.


Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.


var google_conversion_label = "owonCMyG5nEQ0aD71QM";


Submit a Comment

Your email address will not be published. Required fields are marked *

Privacy Preference Center


Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]


Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid


Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie


These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.