Many MySQL users on Ubuntu systems face this frustrating scenario: you set group_concat_max_len
in your my.cnf file, but after restarting MySQL, the value reverts to the default 1024. This happens because MySQL configuration files have a specific hierarchy and syntax requirements that aren't always obvious.
On Ubuntu, MySQL typically reads configuration from multiple locations in this order:
1. /etc/mysql/my.cnf
2. /etc/mysql/conf.d/
3. /etc/mysql/mysql.conf.d/
The key issue is that later files can override earlier ones, and Ubuntu's default MySQL installation often includes overriding configurations.
Here's the correct way to permanently set group_concat_max_len
:
[mysqld]
group_concat_max_len = 15360
This must be placed under the [mysqld]
section in the right configuration file. The most reliable location is:
/etc/mysql/mysql.conf.d/mysqld.cnf
After making changes:
sudo systemctl restart mysql
mysql -u root -p -e "SHOW VARIABLES LIKE 'group_concat_max_len';"
You should see:
+----------------------+-------+
| Variable_name | Value |
+----------------------+-------+
| group_concat_max_len | 15360 |
+----------------------+-------+
If you're using MySQL in Docker, add this to your docker-compose.yml:
environment:
- MYSQL_GROUP_CONCAT_MAX_LEN=15360
- Check all configuration files for conflicting settings
- Verify file permissions (should be readable by mysql user)
- Check MySQL error logs for configuration issues
While increasing this value solves immediate problems, be aware that:
- Higher values consume more memory
- Very large concatenations can impact query performance
- The optimal value depends on your specific use case
Many developers working with MySQL on Ubuntu encounter this frustrating scenario: You add group_concat_max_len=15360
to your my.cnf
file, restart MySQL, only to find the value stubbornly reverts to the default 1024. Let's dive deep into why this happens and how to properly configure it.
MySQL on Ubuntu actually reads configuration from multiple files in this order:
1. /etc/mysql/my.cnf
2. /etc/mysql/conf.d/*.cnf
3. /etc/mysql/mysql.conf.d/*.cnf
4. ~/.my.cnf
The key insight is that later files can override earlier settings, which explains why your changes might not be taking effect.
For Ubuntu systems, the most reliable place to set this is in /etc/mysql/mysql.conf.d/mysqld.cnf
. Here's exactly what to do:
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
Add this under the [mysqld]
section:
[mysqld]
group_concat_max_len = 15360
After making changes, restart MySQL and verify:
sudo systemctl restart mysql
mysql -u root -p -e "SHOW VARIABLES LIKE 'group_concat_max_len';"
Expected output:
+----------------------+-------+
| Variable_name | Value |
+----------------------+-------+
| group_concat_max_len | 15360 |
+----------------------+-------+
If it still doesn't work:
- Check for duplicate settings in other .cnf files
- Ensure you edited the correct [mysqld] section
- Verify file permissions (should be readable by mysql user)
- Check MySQL error logs for configuration issues
For advanced cases where you can't modify the main config, you can use MySQL's init-file feature:
[mysqld]
init-file = /etc/mysql/init.sql
Then create /etc/mysql/init.sql
with:
SET GLOBAL group_concat_max_len=15360;
Remember to restart MySQL after these changes.
For very large concatenations (like exporting entire tables as JSON), you might need even bigger values:
group_concat_max_len = 1048576 # 1MB limit
Just be aware of memory implications when using extremely large values.