简体   繁体   English

MYSQL CONCAT最大长度

[英]MYSQL CONCAT MAX LENGTH

Following this post: POST ABOUT CONCAT My problem is that i have many rows CONCAT into one row. 在这篇文章之后: 关于CONCAT发布我的问题是我有很多行CONCAT变成一行。 For example if i have 10 rows with string around 50 chars, my query will show me only 6-7 of that rows or something like that. 例如,如果我有10行,字符串约50个字符,我的查询将只显示6-7行或类似的内容。 I searech in stack and google and i found that i can change CONCAT max length by command: SET group_concat_max_len := @@max_allowed_packet . 我在stack和google中搜索,发现可以通过以下命令更改CONCAT最大长度: SET group_concat_max_len := @@max_allowed_packet What i am doing wrong? 我做错了什么?

EDIT: When i SHOW VARIABLES LIKE 'group_concat_max_len' it's shows me 1024. Mysql version 5.0.96-log. 编辑:当我SHOW VARIABLES LIKE 'group_concat_max_len'它将显示1024。Mysql版本5.0.96-log。 Tables type: MyISAM. 表类型:MyISAM。 Looks like it dont have any limits, i try to select simple varchar with 2000 chars, and it looks fine. 看起来它没有任何限制,我尝试选择具有2000个字符的简单varchar,它看起来还不错。 I have 3 tables: 1st - Item with ItemID, 2nd - Descriptionpack with ItemID and DescriptionID, 3rd Description with DescriptionID. 我有3个表:第一个-具有ItemID的项目,第二个-具有ItemID和DescriptionID的Descriptionpack,第三个具有DescriptionID的描述。

Select
DISTINCT Item.ItemID as item
,GROUP_CONCAT(Description.DescriptionID) AS description
From Item 
LEFT OUTER JOIN descriptionpack
on Item.ItemID=descriptionpack.ItemID
LEFT OUTER JOIN description
on descriptionpack.descriptionID=description.descriptionID
GROUP BY item

EDIT2: I think i found the problem, i said my problem to my provider and they answer me this: EDIT2:我认为我发现了问题,我向提供者说了我的问题,他们回答了这个问题:

I reviewed your question with our hosting team. 我与我们的托管团队一起审查了您的问题。 You wouldn't be able to change the global settings for that and other variables. 您将无法更改该变量和其他变量的全局设置。 However, you should be able to set that variable on a per session basis by setting it first, before other queries. 但是,您应该能够在每个会话的基础上设置该变量,方法是先设置该变量,然后再进行其他查询。 Hope that helps. 希望能有所帮助。

So now the problem is, how to do that. 所以现在的问题是,如何做到这一点。

Presumably you're using GROUP_CONCAT() , not simple CONCAT() . 大概您正在使用GROUP_CONCAT() ,而不是简单的CONCAT()

The default value of the group_concat_max_len is 1024, which is a pretty small limit if you're building up big long concatenations. group_concat_max_len的默认值为1024,如果要建立大的长串联,则这是一个很小的限制。

To change it, use this command. 要更改它,请使用此命令。 I've set the length in this example to 100,000. 在此示例中,我将长度设置为100,000。 You could set it to anything you need. 您可以将其设置为所需的任何内容。

 SET SESSION group_concat_max_len = 100000;

The usual value for max_allowed_packet is one megabyte, which is likely more than you need. max_allowed_pa​​cket的通常值为1兆字节,可能超出您的需要。

group_concat_max_len itself has an effectively unlimited size . group_concat_max_len本身实际上具有无限大小 It's limited only by the unsigned word length of the platform: 2^32-1 on a 32-bit platform and 2^64-1 on a 64-bit platform. 它仅受平台的无符号字长限制:在32位平台上为2 ^ 32-1,在64位平台上为2 ^ 64-1。

If that still isn't enough for your application, it's time to take @eggyal's suggestion and rethink your approach. 如果这仍不足以满足您的应用程序,那么该是接受@eggyal的建议并重新考虑您的方法的时候了。

You need change group_concat_max_len default value in the bellow config file   
**my.cnf file(Linux) and my.ini file(windows)**   

[mysqld]//Add this line group_concat_max_len=15000 under mysqld section

group_concat_max_len=15000

Note: After change is done You need to restart your MySQL server.   
my.cnf file path in linux :   
 1. /etc/my.cnf   
2./etc/mysql/my.cnf   
3.$MYSQL_HOME/my.cnf   
4.[datadir]/my.cnf   
5.~/.my.cnf  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM