GROUP_CONCAT 中允许的最大长度?如何通过? [英] Maximum length allowed in GROUP_CONCAT ? How to pass it?

查看:55
本文介绍了GROUP_CONCAT 中允许的最大长度?如何通过?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 mySQL 中我使用 GROUP_CONCAT

In mySQL I use GROUP_CONCAT

SELECT
visits,
GROUP_CONCAT(token) as token
FROM general
GROUP BY visits

但问题是我有大量相同访问的行并且使用 PHP 不允许我打印所有内容.

but the problem is that I have a huge number of rows with same visits and using PHP it does not allow me to print everything.

是否有解决方法?

推荐答案

当我尝试 group_concat 一个太大的字符串时遇到了同样的问题..所以我解决这个问题的方法是

I ran into the same issue when I was trying to group_concat a string that was too big.. so what I did to solve it was this

SET SESSION group_concat_max_len = 10000000000000000;

这是一个临时函数,意味着它实际上不会永远改变它,而只会在您的查询会话范围内改变它.

this is a temporary function meaning that it wont actually change it forever but only in the scope of your query session.

我不建议永远改变它,而只是为了你的查询范围......这样你就不会为那个函数占用大量内存空间......当你可能不需要使用时一直都是这样

I wouldn't recommend changing it forever but only for the scope of your query... that way you aren't using up a lot of memory space for that one function.. when you probably don't need to use it all the time

除此之外,如果您真的只想将其重置为更大的长度而不是为您的会话更改它,那么只需从查询中删除会话即可进行设置.

with that aside if you really want to just reset it to a larger length and not change it for your session then just remove session from the query to set it.

所以你的查询应该是这样的

so your query should be like this

SET SESSION group_concat_max_len = 10000000000000000; -- # -- or whatever size you need to make it
SELECT 
    visits,
    GROUP_CONCAT(token) as token
FROM general
GROUP BY visits;

如果您仍然收到@spencer7593 正确指出的错误..您可能需要更改您的max_allowed_pa​​cket...您可以从这个SO POST

if you are still getting an error as @spencer7593 correctly noted.. you may need to change your max_allowed_packet... you can do that from this SO POST

这篇关于GROUP_CONCAT 中允许的最大长度?如何通过?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆