zoukankan      html  css  js  c++  java
  • 8.5.5 Bulk Data Loading for InnoDB Tables 批量数据加载

    8.5.5 Bulk Data Loading for InnoDB Tables 批量数据加载

    当将数据导入到InnoDB,关掉自动提交模式,因为它执行一个log flush 到disk 对每次insert,

    关闭自动提交在你的操作期间:

    SET autocommit=0;
    … SQL import statements …
    COMMIT;

    mysqldump 选项–opt 创建dump 文件快速导入到一个InnoDB表

    mysql> create table t100(id int);
    Query OK, 0 rows affected (0.43 sec)

    mysql> create table t100_idx1 on t100(id);
    ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘on t100(id)’ at line 1
    mysql> create index t100_idx1 on t100(id);
    Query OK, 0 rows affected (0.17 sec)
    Records: 0 Duplicates: 0 Warnings: 0

    mysql> show create table t100G;
    ***************** 1. row *****************
    Table: t100
    Create Table: CREATE TABLE t100 (
    id int(11) DEFAULT NULL,
    KEY t100_idx1 (id)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8
    1 row in set (0.01 sec)

    ERROR:
    No query specified

    如果你有一个唯一约束在第2个索引,你可以加速表导入通过临时的关闭uniqueness checks 。

    SET unique_checks=0;
    … SQL import statements …
    SET unique_checks=1;

    对于大表, 这样可以节省大量的磁盘I/O,因为InnoDB能使用它的改变的buffer 写到第一个索引记录以批量的方式,

    小心数据不能包含重复的记录。

    如果的有外键约束在你的表里,你可以加速表导入通过关掉外键约束检查。

    SET foreign_key_checks=0;
    … SQL import statements …
    SET foreign_key_checks=1;

    对于大表,这个可以节省磁盘I/O:

    如果需要插入多行,使用多行插入语法来减少客户端和服务器之间的通信开销:

    INSERT INTO yourtable VALUES (1,2), (5,5), …;

  • 相关阅读:
    元数据 缓存 池 模式
    ContractPattern 面向面向契约模式
    第三方登录 ----转载自简书,作者 <<碧霄问鼎>>
    证书那些事
    导航(NavanavigationController)push和pop
    iOS app上传错误集锦(转载)
    Block 的基本用法
    正则表达式的用法 转载
    UIView
    UIDate(时间)
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13351415.html
Copyright © 2011-2022 走看看