Problem: When a user up to a certain amount of data, performance issues mysql, how to reduce data storage space below the table to optimize
MySQL comes with compression and decompression functions
1 tabular data compression
270w strip test data storage table (room_record1) memory space 9G
CREATE TABLE `room_record1` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`room` int(11) NOT NULL,
`uuid` varchar(100) NOT NULL,
`info` blob NOT NULL,
`timestamp` int(11) NOT NULL,
`type` int(11) NOT NULL,
PRIMARY KEY (`id`,`timestamp`),
KEY `room` (`room`),
KEY `uuid` (`uuid`),
KEY `idx_timestamp` (`timestamp`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8
Optimization field: info field compression
space:
Optimized table structure:
CREATE TABLE `room_record2` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`room` int(11) NOT NULL,
`uuid` varchar(100) NOT NULL,
`info` blob NOT NULL,
`timestamp` int(11) NOT NULL,
`type` int(11) NOT NULL,
PRIMARY KEY (`id`,`timestamp`),
KEY `room` (`room`),
KEY `uuid` (`uuid`),
KEY `idx_timestamp` (`timestamp`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8
INSERT INTO `room_record2` (`id`, `room`, `uuid`, `info`, `timestamp`, `type`) VALUES ('202737598', '434436', 'f2ba4943-6779-494d-a103-0b86873462a3',compress( '[[0,2,\"4s\",[1,431642,-500,\"1s,1b,2s,2s,2b,2b,3b,4b,5s,8b,9s,9s,9b,Tb\",-2,-2,0,-1,\"194.5\"],[2,634577,295,\"2s,2s,2b,2b,3b,4b,4b,5b,6s,6s,7s,7b,8s,9b\",-2,-2,0,-1,\"829\"],[0,2,2,1,0,1,0,0,1,0,0,0,1,0,1,0,0,0,0,0,0,10,1,0,2,5,{\"min_gold_ka\":3,\"less_score_free\":5,\"limit_enter_battle_score\":50,\"limit_battle_score\":20,\"score_limit_open\":1,\"score_max_limit\":11,\"min_limit_gold_ka\":100,\"score_limit_open1\":1,\"score_max_limit1\":150,\"min_limit_gold_ka1\":300,\"less_score_reback_header\":-1,\"choupai_num\":0,\"tuoguan\":120,\"noreback\":0,\"beilv\":50,\"fanbei\":2,\"less_score\":5,\"fanbei_open\":1,\"add_score_open\":0,\"less_score_add_level\":1,\"add_score\":1,\"hutoall\":0,\"zhangshu\":3,\"changshuang\":1,\"tuoguan_mode\":1}]],[1,2,12,\"4s\",0,0,[[1,0,0],[2,0,0]]],[1,2,11,\"9b\",0,0,[[1,0,0],[2,0,0]]],[2,1,\"2,\"],[1,1,1,\"9b,9s,9s,9b,8b,Tb\",0,0,[[1,0,0],[2,0,0]]],[1,1,11,\"4b\",0,0,[[1,0,0],[2,0,0]]],[2,2,\"1,2,\"],[1,2,2,\"4b,4b,4b\",3,0,[[1,0,0],[2,0,0]]],[1,2,11,\"4s\",3,0,[[1,0,0],[2,0,0]]],[1,2,7,\"4s\",3,0,[[1,0,0],[2,0,0]]],[1,1,12,\"1s\",0,0,[[1,0,0],[2,0,0]]],[2,1,\"2,\"],[1,1,10,\"1s\",0,0,[[1,0,0],[2,0,0]]],[1,1,7,\"1s\",0,0,[[1,0,0],[2,0,0]]],[1,2,12,\"Ts\",3,0,[[1,0,0],[2,0,0]]],[1,1,9,\"\",0,0,[[1,0,0],[2,0,0]]],[1,1,12,\"Ts\",9,0,[[1,0,4],[2,0,-4]]],[3,1,[1,4,4,-500],[2,-4,-4,295],[1,\"1s,1b,2s,2s,2b,2b,3b,5s\"],[2,\"2s,2s,2b,2b,3b,5b,6s,6s,7s,7b,8s\"],[1,2,1,4,-1,0,2,-4,-1,0,3,1,\"Ts\",0,0,29,\"5s\",\"7b\",\"Tb\",\"4b\",\"5b\",\"6s\",\"9b\",\"3s\",\"3s\",\"9s\",\"6b\",\"Tb\",\"1s\",\"4s\",\"8s\",\"Ts\",\"7b\",\"6b\",\"3s\",\"Tb\",\"5b\",\"1b\",\"8b\",\"Ts\",\"7s\",\"7b\",\"5s\",\"5s\",\"7s\",2,1,8,\"1s\",\"1b\",\"2s\",\"2s\",\"2b\",\"2b\",\"3b\",\"5s\",2,11,\"2s\",\"2s\",\"2b\",\"2b\",\"3b\",\"5b\",\"6s\",\"6s\",\"7s\",\"7b\",\"8s\",5,5,0,3,\"9b\",\"9s\",\"9s\",3,0,3,\"9b\",\"8b\",\"Tb\",2,6,3,\"1b\",\"2b\",\"3b\",2,3,3,\"1s\",\"5s\",\"Ts\",5,0,3,\"2s\",\"2s\",\"2b\",9,4,\"Ts\",2,1,4,2,-4,2,434436,1,0,1582128000,4,10,0]]]'), '1582128000', '18');
First explain the type of Blob
1, MySQL BLOB There are four types:
· TINYBLOB: only 255 characters
· blob: a maximum limit to 65K bytes
· mediumblob: limited to 16M bytes
· longblob: up to 4GB
2, in addition to the type of rear access file size limit, but also to modify mysql configuration file.
Windows, linux basic as by modifying the file my.ini or my.cnf file, add max_allowed_packet = 10M in the file (that is, the maximum 10M, mysql default seems to 1MB, to ensure that no increase before to find what set off)
3, do the above settings after a little while to upload larger files or if an error or when certain documents, such as newspaper gibberish, it is estimated that the following problem.
Problems character set table or database, such as the hibernate connection utf-8, and other tables are gbk, generally as long as the data provided on the line connecting portion hibernate, such as
jdbc: mysql: //192.168.0.4: 3306 / test useUnicode = true & characterEncoding =? UTF-8
- Compression
using the function COMPRESS: COMPRESS (COL) can, as shown, is a compression test of one. Column format for storing compressed data as binary format blob BLOB field, a container can store large amounts of data), the compression rate can reach 80 to 90% - Decompression
using the function UNCOMPRESS: UNCOMPRESS (col) can be, due to the compressed format is the amount of future generations blob, then the format after decompression is also blob, had to convert to a layer to view, as follows:
select id,info '存储的',UNCOMPRESS(info)'解压的' ,cast(UNCOMPRESS(info) as char) '解压并转换' from room_record2
Table (room_record2) Data:
Optimization of compressed data storage:
Summary: Table Column compression can save 60% effect table storage space, the result is more objective
Table 2 Data Compression
Can refer to
Table Compression: https: //www.cnblogs.com/mysql-dba/p/5125220.html