This article describes how to implement MySQL batch compression for MYISAM tables. The example shows how MySQL uses shell commands to batch compress MYISAM tables, for more information about MySQL batch compression, see the following example. We will share this with you for your reference. The details are as follows:
For compression of MYISAM tables, you can use myisampack and myisamchk (myisamchk must be used after myisampack to use the compressed table, and it is read-only ), for detailed usage, refer to the official documentation:
Http://dev.mysql.com/doc/refman/5.1/zh/client-side-scripts.html.
These two operations need to be used with caution. before compression, you need to confirm that mysqld is disabled or that the table to be compressed does not have any other SQL operations, and the compression process will occupy cpu resources, we recommend that you do this when the server is idle.
The following is the shell process used to compress the following table of a database (it is worth noting that if the data volume is large, we recommend that you perform the operation multiple times because it takes a lot of time ):
#! /Bin/bashdata_dir = "/data/mysql/my_dbname/" filelist = 'ls $ data_dir 'echo "myisampack begin. "for filename in $ filelistdo idx = 'expr match" $ filename "". *. MYI "'if [[$ idx> 0] then/usr/bin/myisampack $ data_dir $ filename fidoneecho" MYISAMPACK End. myisamchk begin. "for filename in $ filelistdo idx = 'expr match" $ filename "". *. MYI "'if [[$ idx> 0] then/usr/bin/myisamchk-r-o-f -- sort-index -- analyze $ data_dir $ filename fidoneecho" myisamchk end."