zoukankan      html  css  js  c++  java
  • 每天进步一点达——MySQL——myisampack

    一、        简单介绍

             myisampack是一个压缩使用MyISAM引擎表的工具,通常会压缩40%~70%,当须要訪问数据。server会将所须要的信息读入到内存中。所以当訪问详细记录时,性能会更好,由于仅仅须要解压一条记录

             MySQL使用mmap()对变哦进行压缩映射,假设mmap()不工作,MySQL会返回到普通的读写文件操作

             压缩后的表将会成为仅仅读的,而且myisampack不支持分区表。

    二、       命令格式

    myisampack 选项 文件名称

    三、       经常使用參

             --backup-b --backup   使用tbl_name .OLD备份数据文件

             --force  -f  产生一个压缩的表。即使它比原始表大,或假设曾经调用myisampack的中间文件存在。(myisampack压缩表时在数据库文件夹中创建一个名为tbl_name.TMD的中间文件。

    假设杀掉myisampack。.TMD文件会被删除)。

    通常情况。假设myisampack发现tbl_name.TMD存在则退出并提示错误。用--force,myisampack则一定压缩表。

        --join=big_tbl_name  -j big_tbl_name 将命令行中的全部表联接为一个表big_tbl_name。将要连接的全部表必须有相等的结构(同样的列名和类型,同样的索引等等)。

        --packlength=len,-p len 指定记录长度存储大小,以字节计。

    值应为1、2或者3。myisampack保存全部长度指针为1、2或者3字节的行。在大多数正常情况下,myisampack在開始压缩文件前能够确定准确的长度值。但在压缩过程中它能够提示它可能已经使用了一个短的长度。在这样的情况下。myisampack输出一条提示,下次你压缩同一文件时,你能够使用更短的记录长度。

        --silent,-s 沉默模式。

    仅仅有错误发生时才写输出。

        --test,-t 没有实际地压缩表。仅仅是測试压缩。

        --tmpdir=path,-T path 使用myisamchk创建暂时文件的文件夹。

        --verbose,-v 冗长模式。写压缩操作过程相关信息和其结果。

        --version。-V 显示版本号信息并退出。

        --wait,-w 假设表正使用则等待并重试。假设用--skip-external-locking选项调用了mysqldserver。假设在压缩过程中表可能被更新,调用myisampack不是一个好主意。

        执行myisampack后。必须执行myisamchk以又一次创建索引。

    此时,你也能够排序索引块并创建MySQL优化器须要的统计信息以更有效地工作:  shell> myisamchk -rq --sort-index--analyze tbl_name.MYI 将压缩的表安装到MySQL数据库文件夹中后。应执行mysqladmin flush-tables以强制mysqld使用新的表。  要想解压缩一个压缩的表,使用myisamchk或isamchk的--unpack选项。

             --help      帮助

              

    四、       经常使用样例

    1.   myisampack压缩表

    [root@localhosttest2]# ll -tr

    总用量 180

    -rw-rw---- 1 mysql mysql     65 7月  16 16:40 db.opt

    -rw-rw---- 1 mysql mysql   8556 7月  16 16:46 t1.frm

    -rw-rw---- 1 mysql mysql   1024 7月  16 17:29 t1.MYI

    -rw-rw---- 1 mysql mysql 161742 7月  16 17:29 t1.MYD

     [root@localhost test2]# myisampack t1

    Compressing t1.MYD: (23106 records)

    - Calculating statistics

    - Compressing file

    85.68%    

    [root@localhosttest2]# ll -tr

    总用量 44

    -rw-rw---- 1 mysql mysql    65 7月  16 16:40 db.opt

    -rw-rw---- 1 mysql mysql  8556 7月  16 16:46 t1.frm

    -rw-rw---- 1 mysql mysql 23167 7月  16 17:29 t1.MYD

    -rw-rw---- 1 mysql mysql  1024 7月  16 17:30 t1.MYI

    在Mysql中查询

    mysql>show table status like 't1'G;

    *************************** 1. row***************************

              Name: t1

            Engine: MyISAM

           Version: 10

        Row_format: Fixed

              Rows: 22857

     Avg_row_length: 7

       Data_length: 159999

    Max_data_length: 1970324836974591

      Index_length: 1024

         Data_free: 0

     Auto_increment: NULL

       Create_time: 2015-07-16 16:46:17

       Update_time: 2015-07-16 17:29:40

        Check_time: NULL

         Collation: latin1_swedish_ci

          Checksum: NULL

     Create_options:

           Comment:

    1 row in set (0.00 sec)

    ERROR:

    No query specified

    mysql>show table status like 't1'G;

    *************************** 1. row***************************

              Name: t1

            Engine: MyISAM

           Version: 10

        Row_format: Fixed

              Rows: 23177

     Avg_row_length: 7

       Data_length: 162239

    Max_data_length: 1970324836974591

      Index_length: 1024

         Data_free: 0

     Auto_increment: NULL

       Create_time: 2015-07-16 16:46:17

       Update_time: 2015-07-16 17:30:48

        Check_time: NULL

         Collation: latin1_swedish_ci

          Checksum: NULL

     Create_options:

           Comment:

    1 row in set (0.00 sec)

    t8      lines: 7        columns: 9

    2.   myisampack备份数据库文件

     [root@localhost test2]# ll

    -rw-rw---- 1 mysql mysql      65 7月  16 16:40 db.opt

    -rw-rw---- 1 mysql mysql    8572 7月  17 09:28 t1.frm

    -rw-rw---- 1 mysql mysql      73 7月  17 09:50 t1.MYD

    -rw-rw---- 1 mysql mysql    1024 7月  17 10:04 t1.MYI

    -rw-rw---- 1 mysql mysql      217月  17 09:50 t1.OLD

    -rw-rw---- 1 mysql mysql    8598 7月  17 10:10 t2.frm

    -rw-rw---- 1 mysql mysql4344192 7  17 10:11 t2.MYD

    -rw-rw---- 1 mysql mysql 4955136 7月  17 10:11 t2.MYI

    -rw-rw---- 1 mysql mysql    8572 7月  17 10:06 t3.frm

    -rw-rw---- 1 mysql mysql  147456 7月  17 10:06 t3.ibd

    -rw-rw---- 1 mysql mysql    8598 7月  17 10:11 t4.frm

    -rw-rw---- 1 mysql mysql 4344192 7月  17 10:11 t4.MYD

    -rw-rw---- 1 mysql mysql    1024 7月  17 10:11 t4.MYI

    -rw-rw---- 1 mysql mysql    8598 7月  17 10:12 t5.frm

    -rw-rw---- 1 mysql mysql 1996157 7月  17 10:12 t5.MYD

    -rw-rw---- 1 mysql mysql    1024 7月  17 10:12 t5.MYI

    -rw-rw---- 1 mysql mysql4344192 7  17 10:12 t5.OLD

    我们发现备份出来的数据文件与原来的文件大小一致。可是压缩后的数据文件会小一些

    3.   向T5中插入数据

    mysql> insert into t5(str_number)values(1);

    ERROR 1036 (HY000): Table 't5' is read only


     

  • 相关阅读:
    SCILAB简介[z]
    UG OPEN API编程基础 2约定及编程初步
    Office 2003与Office 2010不能共存的解决方案
    UG OPEN API 编程基础 3用户界面接口
    NewtonRaphson method
    UG OPEN API编程基础 13MenuScript应用
    UG OPEN API编程基础 14API、UIStyler及MenuScript联合开发
    UG OPEN API编程基础 4部件文件的相关操作
    UG OPEN API编程基础 1概述
    16 UG Open的MFC应用
  • 原文地址:https://www.cnblogs.com/mfrbuaa/p/5342882.html
Copyright © 2011-2022 走看看