How to increase MySQL GROUP_CONCAT() maximum length

Summary
In this post, we will learn how to check & increase the MySQL GROUP_CONCAT() maximum length.
The MySQL GROUP_CONCAT() function is an aggregate function that converts multiple rows into a single string. However, the default character length support GROUP_CONCAT function is 1024 characters.
To check the GROUP_CONCAT length in your MySQL, run the below commands.
SHOW VARIABLES LIKE '%GROUP_CONCAT%'
and will be output something like this if default value is not changed
group_concat_max_len 1024
So if your query required more than 1024 characters, then there is an option you can increase the GROUP_CONCAT characters length as per your requirement. by changing the system variable group_concat_max_len which can change at runtime by using the SET command.
SET [GLOBAL | SESSION] group_concat_max_len = value;
So here you can see there is two option available to change the group_concat_max_len system variable-length GLOBAL & SESSION. Let's see both examples.
Below will set for GLOBAL.
SET GLOBAL group_concat_max_len = 1048576;
Below will set for current SESSION.
SET SESSION group_concat_max_len = 1048576;
Conclusion
This is a simple post about how to increase the MySQL GROUP_CONCAT() max length. I hope you like this article.
You May Like:Creating a REST API with Lumen