MySql數據庫查詢時,使用group_concat報錯“Row XXX was cut by GROUP_CONCAT()”,查了下是因為group_concat有個最大長度的限制,超過最大長度就會被截斷掉,
我們檢查一下mysql的全局環境變量:
mysql> SELECT @@global.group_concat_max_len; +-------------------------------+ | @@global.group_concat_max_len | +-------------------------------+ | 1024 | +-------------------------------+
檢查一下是將生產環境的查詢字段的的最大長度:
mysql> select max(length(extra)) from credit.apply; +--------------------+ | max(length(extra)) | +--------------------+ | 9599 | +--------------------+
再檢查一下最大聚合次數
mysql> select max(c1) from (select custid,count(1) as c1 from credit.apply group by custid )t; +---------+ | max(c1) | +---------+ | 58 | +---------+
所以估計最大可能出現的長度為
9599 *58+67=556809
可以改變group_concat_max_len變量解決該問題:
SET group_concat_max_len=556809;
