zoukankan      html  css  js  c++  java
  • Mysql:The CSV Storage Engine

     注意:

      1)表定义(换句话说)数据列必须不能为空Null!

      2)修复表,极有可能丢失数据

    16.4 The CSV Storage Engine

    The CSV storage engine stores data in text files using comma-separated values format.

    The CSV storage engine is always compiled into the MySQL server.

    To examine the source for the CSV engine, look in the storage/csv directory of a MySQL source distribution.

    When you create a CSV table, the server creates a plain text data file having a name that begins with the table name and has a .CSV extension. When you store data into the table, the storage engine saves it into the data file in comma-separated values format.

    mysql> CREATE TABLE test (i INT NOT NULL, c CHAR(10) NOT NULL)
           ENGINE = CSV;
    Query OK, 0 rows affected (0.06 sec)
    
    mysql> INSERT INTO test VALUES(1,'record one'),(2,'record two');
    Query OK, 2 rows affected (0.05 sec)
    Records: 2  Duplicates: 0  Warnings: 0
    
    mysql> SELECT * FROM test;
    +---+------------+
    | i | c          |
    +---+------------+
    | 1 | record one |
    | 2 | record two |
    +---+------------+
    2 rows in set (0.00 sec)
    

    Creating a CSV table also creates a corresponding metafile that stores the state of the table and the number of rows that exist in the table. The name of this file is the same as the name of the table with the extension CSM.

    If you examine the test.CSV file in the database directory created by executing the preceding statements, its contents should look like this:

    "1","record one"
    "2","record two"

    This format can be read, and even written, by spreadsheet applications such as Microsoft Excel or StarOffice Calc.

    16.4.1 Repairing and Checking CSV Tables

    The CSV storage engine supports the CHECK TABLE and REPAIR TABLE statements to verify and, if possible, repair a damaged CSV table.

    When running the CHECK TABLE statement, the CSV file will be checked for validity by looking for the correct field separators, escaped fields (matching or missing quotation marks), the correct number of fields compared to the table definition and the existence of a corresponding CSV metafile. The first invalid row discovered will report an error. Checking a valid table produces output like that shown below:

    mysql> CHECK TABLE csvtest;
    +--------------+-------+----------+----------+
    | Table        | Op    | Msg_type | Msg_text |
    +--------------+-------+----------+----------+
    | test.csvtest | check | status   | OK       |
    +--------------+-------+----------+----------+
    

    A check on a corrupted table returns a fault:

    mysql> CHECK TABLE csvtest;
    +--------------+-------+----------+----------+
    | Table        | Op    | Msg_type | Msg_text |
    +--------------+-------+----------+----------+
    | test.csvtest | check | error    | Corrupt  |
    +--------------+-------+----------+----------+
    

    If the check fails, the table is marked as crashed (corrupt). Once a table has been marked as corrupt, it is automatically repaired when you next run CHECK TABLE or execute a SELECT statement. The corresponding corrupt status and new status will be displayed when running CHECK TABLE:

    mysql> CHECK TABLE csvtest;
    +--------------+-------+----------+----------------------------+
    | Table        | Op    | Msg_type | Msg_text                   |
    +--------------+-------+----------+----------------------------+
    | test.csvtest | check | warning  | Table is marked as crashed |
    | test.csvtest | check | status   | OK                         |
    +--------------+-------+----------+----------------------------+
    

    To repair a table, use REPAIR TABLE, which copies as many valid rows from the existing CSV data as possible, and then replaces the existing CSV file with the recovered rows. Any rows beyond the corrupted data are lost.

    mysql> REPAIR TABLE csvtest;
    +--------------+--------+----------+----------+
    | Table        | Op     | Msg_type | Msg_text |
    +--------------+--------+----------+----------+
    | test.csvtest | repair | status   | OK       |
    +--------------+--------+----------+----------+
    
    Warning

    During repair, only the rows from the CSV file up to the first damaged row are copied to the new table. All other rows from the first damaged row to the end of the table are removed, even valid rows.

    16.4.2 CSV Limitations

    The CSV storage engine does not support indexing.

    The CSV storage engine does not support partitioning.

    All tables that you create using the CSV storage engine must have the NOT NULL attribute on all columns.

  • 相关阅读:
    常见协议基础知识总结--FTP协议
    DG增量恢复
    DG备库无法接受主库归档日志之密码文件
    Oracle密码概要文件,密码过期时间180天修改为3天,相关用户密码是否过期
    ORA-15025 搭建DG环境,restore controlfile报错,提示oracle无法使用ASM存储
    Deinstall卸载RAC之Oracle软件及数据库+GI集群软件
    增加临时表空间组Oracle11g单实例
    安装12C小问题及pdb表空间配置
    判断子表外键约束参数类型
    创建small表空间size32G报错ORA-01144
  • 原文地址:https://www.cnblogs.com/jinzhenshui/p/12508487.html
Copyright © 2011-2022 走看看