Mysql big field problem

Some time ago, during the stress test of the project, there was a large field problem in MySQL, which caused the data layer to fail to store. All parties looked for help, but to no avail. Finally, they turned to the almighty google and found a solution from foreign experts. Step by step, it was finally solved. I didn't write a summary later, I just wrote a simple Youdaoyun note. As a result, the online version has this problem again today, so I can't help but blame myself for not posting a detailed blog post record and sharing it with Brothers (there is no way that I have been too busy recently, and I have been busy flying).

 

【Problem Description】

The earliest mysql side reported this error

Row size too large. The maximum row size for the used table type, not counting BLOBs, is 8126. You have to change some columns to TEXT or BLOBs

 

Errors in today's online version:

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Row size too large (> 8126). Changing some columns to TEXT or BLOB or using ROW_FORMAT=DYNAMIC or ROW_FORMAT=COMPRESSED may help. In current row format, BLOB prefix of 768 bytes is stored inline.

 

【Cause of the problem】

The reason is summarized because mysql-innodb stores data according to the page, the max size of each page is 16k, and then there are two rows of data per page, so the maximum data per row is 8k. If your field is a blob or the like, it will be stored in the overflow area outside the page.

However, the default approach (antelope) storage format of innodb will store the first 864 bytes of each blob field in the page, so if your blob exceeds a certain number, the size of a single line will exceed 8k, so an error will be reported.

【Solutions】

The solution is to use innodb's Barracuda (Barracuda) storage format

The way this format handles the blob field is that only a 20byte pointer is stored in the page, and the others all exist in the overflow area, so you can't easily exceed 8k

 

【detailed steps】

1. Open the mysql configuration my.ini. Add in the innodb configuration: innodb_file_per_table=1

Mysql big field problem

The general meaning is to open the switch that each table in mysql is an independent storage space.

 

2. Then command to check if the above switch is turned on.

show variables like '%per_table%';

 

Mysql big field problem

The switch is turned on as shown above.

 

3. Set the mysql global variable: innodb_file_format = Barracuda (Barracuda)

命令:set GLOBAL innodb_file_format = 'Barracuda';

Then check if it's set up:

命令:show GLOBAL VARIABLES LIKE '%file_format%';

 

Mysql big field problem

It's good as above

 

4. Set the properties of the corresponding table: ROW_FORMAT=COMPRESSED

Then check if the subscripted property is what you set: COMPRESSED

 

5. After the above steps, it is OK

 

 

Let tx toss for another day today, MD. Long-term memory, no matter how busy you are, you must record it and share it with the team. I hope our team, my brothers, and our company will accumulate more and more wealth.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326107294&siteId=291194637