MySQL GROUP_CONCAT maximum length and group_concat_max_len
Codemia Knowledge Hub ·
GROUP_CONCAT() results are capped by the group_concat_max_len system variable, which defaults to 1024 bytes. Anything longer is truncated to that length without an error. Raise the limit with SET SESSION group_concat_max_len = ... for the current connection, SET GLOBAL for the server, or in my.cnf to keep it across restarts.
How GROUP_CONCAT() works
GROUP_CONCAT() is an aggregate function like SUM() or COUNT(), but instead of computing a number it concatenates string values from multiple rows into a single string. The typical use is collecting the values of a column for each group into one comma-separated list.
For a table orders with order_id, customer_id and product_name, this lists each customer's products:
Raising group_concat_max_len
<new_max_value> is a positive integer: the byte limit for the concatenated result.
To make the change persistent across server restarts, set it in the MySQL configuration file (my.cnf or my.ini):
Then restart the MySQL service.
| Configuration Variable | Default Value | Maximum Possible Value |
group_concat_max_len | 1024 bytes | 18446744073709551615 on 64-bit platforms, 4294967295 on 32-bit |
Truncation, character sets and memory
- Truncation is silent: when the result exceeds
group_concat_max_len, MySQL cuts it to the maximum length without failing the query. - Character set: the limit is in bytes, so the number of characters you get depends on the character set, since some characters take more than one byte.
- Performance: a higher limit allows larger strings, which can raise memory consumption when you concatenate large values extensively.
- Result size: make sure the increase matches what your application needs and does not exceed storage or transmission limits.
For example, with exceptionally long product names:
Ordering, NULLs and DISTINCT
- Order:
GROUP_CONCAT()respects anORDER BYinside the call. If order matters, specify it. - NULLs:
NULLvalues are skipped. Handling them differently needs extra SQL conditions. - DISTINCT: removes duplicate values, for example to list the unique products ordered each day:
Related reading
- MySQL, better to insert NULL or empty string?
- MySQL between clause not inclusive?
- MySQL C async methods doesn't work?
- MySQL Cannot Add Foreign Key Constraint
- MySQL Cannot drop index needed in a foreign key constraint
- MySQL Can't create table errno 150
- MySQL case sensitive query
- mysql CHANGE MASTER TO command's MASTER_HOST's length limitation
System design interview problems on this topic
- Design a Distributed OLTP Database: solution and walkthrough
- Design a Wide Column Database: solution and walkthrough
- Design a Key Value Store: solution and walkthrough
- Design a Web Cache: solution and walkthrough

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseSystem Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.