Heim >Datenbank >MySQL-Tutorial >【转】MYISAM表批量压缩_MySQL

【转】MYISAM表批量压缩_MySQL

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-01 13:29:21983Durchsuche

bitsCN.com

关于对MYISAM表的压缩,可以使用myisampack和myisamchk完成(myisampack完之后必须进行myisamchk才能使用压缩后的表,而且是只读的), 其详细地用法可以参考官方文档: http://dev.mysql.com/doc/refman/5.1/zh/client-side-scripts.html。

这两个操作需要谨慎使用,在压缩之前需要确认mysqld已关闭或者要压缩的表不会有其他的sql操作;而且压缩过程会很占用cpu资源,建议在服务器空闲的状态进行。

下面是用于实现某数据库下表压缩的shell过程(值得注意的是,如果数据量大,建议分多次操作,因其会很耗时):

 1 #!/bin/bash 2 data_dir="/data/mysql/my_dbname/" 3 filelist=`ls $data_dir` 4 echo "MYISAMPACK BEGIN." 5 for filename in $filelist 6 do 7     idx=`expr match "$filename" ".*.MYI"` 8     if [[ $idx>0 ]] 9     then10         /usr/bin/myisampack $data_dir$filename11     fi12 done13 14 echo "MYISAMPACK End. MYISAMCHK BEGIN."15 16 for filename in $filelist17 do18     idx=`expr match "$filename" ".*.MYI"`19     if [[ $idx>0 ]]20     then21         /usr/bin/myisamchk -r -o -f --sort-index --analyze $data_dir$filename22     fi23 done24 echo "MYISAMCHK END."

 

 

bitsCN.com
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn