How to compress columns in MySQL?

拈花ヽ惹草 提交于 2019-12-24 03:11:03

问题


I have a table which stores e-mail correspondences. Every time someone replies, the whole body of the trail is also included and saved into the database (and I need it that way because the amount of application level changes to rectify that are going to be too high).

The size of the mail text column is 10000. But, I am having trouble storing text more than that. As I am not sure, how many correspondences can occur, I don't know what a good number will be for the column.

The engine is InnoDB. Can I use some kind of columnar compression technique in MySQL to avoid increasing the size of the column?

And, what if I go ahead and increase the varchar column to, say, 20000. The table has about 2 million records. Will that be a good thing to do?


回答1:


You are probably looking for MySQL COMPRESS() and UNCOMPRESS() function to compress data for storage and retrieval respectively.

Also look at InnoDB Compression Usage.




回答2:


As long as the data doesn't need editing, you can use the archive engine.




回答3:


This answer is specific to Percona

Percona introduced a compressed column format a while ago. That you can use on CREATE or ALTERs

CREATE TABLE test_compressed (
    id INT NOT NULL PRIMARY KEY,
    value MEDIUMTEXT COLUMN_FORMAT COMPRESSED
 );

Reference: https://www.percona.com/doc/percona-server/5.7/flexibility/compressed_columns.html



来源:https://stackoverflow.com/questions/30910670/how-to-compress-columns-in-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!