开发者

Reduce data size of a table in MySQL

In one of table, there are around 900 thousand records. when we checked the data size it is around 800 MB. Can we reduce the data size with out deleting data.

Thanks In Advance.


CREATE TABLE snmptraps(
 SiteID int(11) NOT NULL default 1,
 SystemID int(11) NOT NULL,
 EnterpriseID varchar(255) default NULL,
 IPAddress varchar(255) default NULL,
 GenericTrap varchar(255) default NULL,
 SpecificTrap varchar(255) default NULL,
 TimestampGen varchar(255) default NULL,
 TimestampRec datetime default NULL,
 OID varchar(1024) default NULL,
 OIDValue varchar(1024) default NULL,
 TimePeriod TIMESTAMP NOT NULL default CURRENT_TIMESTAMP,
 P开发者_开发知识库DUType int(11),
 Description varchar(255) default NULL,
);


try

optimize table your_table;

After doing substantial insert, update, or delete operations on an InnoDB table that has its own .ibd file because it was created with the innodb_file_per_table option enabled. The table and indexes are reorganized, and disk space can be reclaimed for use by the operating system.

https://dev.mysql.com/doc/refman/8.0/en/optimize-table.html


Use PROCEDURE ANALYSE() to get suggestions about possible optimisations in datatypes. Just be aware, these are just automatic suggestions, and you still should use your own judgement, basing on your application needs.

Also: is that MyISAM or InnoDB? What's the structure of the table?


You can reduce the size of your indices (esp: char/varchar/text columns).

Also: If you are using innodb and you use a default setup, the data file (e.g. ibdata1) can only grow - even if you drop tables.

May want to look into the innodb_file_per_table option: http://dev.mysql.com/doc/refman/5.5/en/innodb-multiple-tablespaces.html


If your use-case allows that you may consider the MySQL archive storage engine. This will certainly free a lot of space. But this depends on the usage of your table.

Removing unnecessary indices, rechecking column types, etc may also help. But again this is bound to the needs of your application(s).

Cheers!


Here are the few steps which I have followed for my database and I get better performance.

Design your tables to minimize their space on the disk. This can result in huge improvements by reducing the amount of data written to and read from disk.

Table Columns Row Format Indexes

Here are the all details for all the options.


you can minimize the output to be easier to copy from host to another one

host:~ $ mysqldump -uroot -p database snmptraps | gzip > snmptraps.sql.gz
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜