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

Detailed explanation of the correct use of the if function in MySQL

For what I am going to write today, the program r...

Detailed explanation of Angular data binding and its implementation

Table of contents Preface What is data binding? T...

Detailed explanation of MySQL database Event scheduled execution tasks

1. Background As the project's business conti...

In-depth explanation of the style feature in Vue3 single-file components

Table of contents style scoped style module State...

WeChat applet uses canvas to draw clocks

This article shares the specific code of using ca...

mysql8.0.11 winx64 installation and configuration tutorial

The installation tutorial of mysql 8.0.11 winx64 ...

A brief discussion on Vue3 father-son value transfer

Table of contents From father to son: 1. In the s...

Better looking CSS custom styles (title h1 h2 h3)

Rendering Commonly used styles in Blog Garden /*T...

Nginx try_files directive usage examples

Nginx's configuration syntax is flexible and ...

Method example of safely getting deep objects of Object in Js

Table of contents Preface text parameter example ...

Change the MySQL database engine to InnoDB

PS: I use PHPStudy2016 here 1. Stop MySQL during ...

Detailed usage of js array forEach instance

1. forEach() is similar to map(). It also applies...

About WSL configuration and modification issues in Docker

https://docs.microsoft.com/en-us/windows/wsl/wsl-...

Vue uniapp realizes the segmenter effect

This article shares the specific code of vue unia...