MySQL之MyISAM儲存引擎壓縮表

來源:互聯網
上載者:User

標籤:結構   膨脹   arch   sig   ber   sel   mys   mem   sed   

一、介紹

MySQL的MyISAM儲存引擎支援壓縮資料表空間,壓縮後的資料表空間會減少,但是壓縮後的表是唯讀,不能插入和更新資料,如果需要更新,則需要解壓後更新,再壓縮 。

二、案例

1.建立資料庫,建立表並指定儲存引擎為MyISAM,字元集為utf8

create database myisamdb;use myisamdb;create table myisam(id int unsigned auto_increment primary key, name varchar(20) not null )engine=myisam charset=utf8;

2.將資料插入到表myisam表中

insert into myisam(name) values(‘聯想tinkpad‘),(‘Dell外星人‘),(‘雷神玄武‘),(‘mac pro‘);

3.使用蠕蟲複製將myisam資料表空間迅速膨脹

mysql> insert into myisam select null,name from myisam;Query OK, 262144 rows affected (1.00 sec)Records: 262144  Duplicates: 0  Warnings: 0

4.查看壓縮前的myisam資料表空間大小

[[email protected] myisamdb]# ls -lh myisam*-rw-rw---- 1 mysql mysql 8.4K 2月  12 20:00 myisam.frm-rw-rw---- 1 mysql mysql  12M 2月  12 20:06 myisam.MYD-rw-rw---- 1 mysql mysql 5.2M 2月  12 20:06 myisam.MYI

5.使用myisampack命令將myisam資料表空間進行壓縮 

[[email protected] myisamdb]# myisampack  myisamCompressing myisam.MYD: (524288 records)- Calculating statistics- Compressing file47.89%     Remember to run myisamchk -rq on compressed table

6.查看壓縮後的myisam資料表空間大小

[[email protected] myisamdb]# ls -lh myisam*-rw-rw---- 1 mysql mysql 8.4K 2月  12 20:00 myisam.frm  #表結構檔案-rw-rw---- 1 mysql mysql 6.0M 2月  12 20:06 myisam.MYD  #資料表空間檔案-rw-rw---- 1 mysql mysql 1.0K 2月  12 20:07 myisam.MYI  #表索引檔案

  

7.由於壓縮後資料表空間會改變,導致索引找不到記錄對應的索引位置,所以要恢複索引

[[email protected] myisamdb]# myisamchk -rq myisam- check record delete-chain- recovering (with sort) MyISAM-table ‘myisam‘Data records: 524288- Fixing index 1  

8.查看恢複的索引檔案大小

[[email protected] myisamdb]# ls -lh myisam*-rw-rw---- 1 mysql mysql 8.4K 2月  12 20:00 myisam.frm-rw-rw---- 1 mysql mysql 6.0M 2月  12 20:06 myisam.MYD-rw-rw---- 1 mysql mysql 5.1M 2月  12 20:08 myisam.MYI

  

 

 

 

 

MySQL之MyISAM儲存引擎壓縮表

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.