How to modify the length limit of group_concat in Mysql

How to modify the length limit of group_concat in Mysql

In MySQL, there is a function called "group_concat". You may not find any problems in normal use. When processing big data, you will find that the content is intercepted. In fact, MYSQL has settings for this. The default length is 1024. If we need a larger length, we need to modify it manually.

The detailed instructions are as follows:

  • After using group_concat, if limit is used in select, it will not work.
  • There is a length limit when using group_concat to concatenate fields. You cannot concatenate as many fields as you want. But you can set it up.
  • Using the group_concat_max_len system variable, you can set the maximum allowed length.
  • The default separator is comma.

Modification method:

SET [SESSION | GLOBAL] group_concat_max_len = 10240;

The editable parameters are as follows:

GROUP_CONCAT accumulates the value of a field according to the specified characters. The system default separator is a comma, and the length of characters that can be accumulated is 1024 bytes.

1. Let’s take a simple example

select group_concat(f_a) from t_one group by f_b;

Perform group query by f_b and accumulate f_a in each group.

2. Modify the default separator

select group_concat(f_a separator '_') from t_one group by f_b;

separator is a keyword followed by the character to be used as separator

3. Sorting

select group_concat(f_a order by f_a separator '_') from t_one group by f_b;

4. Modify the default character size

1) Add to the MySQL configuration file

group_concat_max_len = 102400 #The maximum length you want

2) It can be simpler, execute statements, and set the scope

 SET GLOBAL group_concat_max_len=102400;
 SET SESSION group_concat_max_len=102400;

5. Use with concat

By default, group_concat returns a BLOB object. You can use concat to return a string and add other data to the returned content.

Summarize

The above is what I introduced to you on how to modify the length limit of group_concat in Mysql. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

You may also be interested in:
  • Analysis of the Principle of MySQL Index Length Limit
  • Let's talk about the size and length limits of various objects in MySQL

<<:  Interpretation of Vue component registration method

>>:  CentOS 7 method to modify the gateway and configure the IP example

Recommend

How to install and uninstall open-vswitch in Linux

1. Compile and install ovs from source code: Inst...

Detailed explanation of TS object spread operator and rest operator

Table of contents Overview Object rest attribute ...

The perfect solution for MySql version problem sql_mode=only_full_group_by

1. Check sql_mode select @@sql_mode The queried v...

H tags should be used reasonably in web page production

HTML tags have special tags to handle the title of...

How to limit the number of records in a table in MySQL

Table of contents 1. Trigger Solution 2. Partitio...

Detailed explanation of log processing of Docker containers

Docker has many log plug-ins. The default is to u...

MySQL high concurrency method to generate unique order number

Preface After this blog post was published, some ...

Making a simple game engine with React Native

Table of contents Introduction Get started A brie...

VUE implements timeline playback component

This article example shares the specific code of ...

The difference between MySQL database stored procedures and transactions

Transactions ensure the atomicity of multiple SQL...

CSS3 radar scan map sample code

Use CSS3 to achieve cool radar scanning pictures:...

Difference between MySQL update set and and

Table of contents Problem Description Cause Analy...

Detailed tutorial on installing mysql under Linux

1. Shut down the mysql service # service mysqld s...

Correct modification steps for Docker's default network segment

background A colleague is working on his security...

Detailed explanation of nmcli usage in CentOS8

Common nmcli commands based on RHEL8/CentOS8 # Vi...