zoukankan      html  css  js  c++  java
  • MySQL 加快导入数据

    1.临时关闭binlog,避免写入日志

    set sql_log_bin = off;
    
    mysql> show VARIABLES like '%log_bin%';
    +---------------------------------+------------------------------------------+
    | Variable_name                   | Value                                    |
    +---------------------------------+------------------------------------------+
    | log_bin                         | ON                                       |
    | log_bin_basename                | /opt/mysql/data/3306/mysql3306_bin       |
    | log_bin_index                   | /opt/mysql/data/3306/mysql3306_bin.index |
    | log_bin_trust_function_creators | ON                                       |
    | log_bin_use_v1_row_events       | OFF                                      |
    | sql_log_bin                     | OFF                                      |
    +---------------------------------+------------------------------------------+
    6 rows in set (0.00 sec)
    

    2.临时调整 innodb_flush_log_at_trx_commit ;加快速度刷新数据到硬盘

    set global innodb_flush_log_at_trx_commit=2;
    
    mysql>  SHOW GLOBAL VARIABLES LIKE 'innodb_flush_log%';
    +--------------------------------+-------+
    | Variable_name                  | Value |
    +--------------------------------+-------+
    | innodb_flush_log_at_timeout    | 1     |
    | innodb_flush_log_at_trx_commit | 1     |
    +--------------------------------+-------+
    2 rows in set (0.00 sec)
    
    mysql> set global innodb_flush_log_at_trx_commit=2;
    Query OK, 0 rows affected (0.00 sec)
    
    mysql>  SHOW GLOBAL VARIABLES LIKE 'innodb_flush_log%'; --验证修改状态
    +--------------------------------+-------+
    | Variable_name                  | Value |
    +--------------------------------+-------+
    | innodb_flush_log_at_timeout    | 1     |
    | innodb_flush_log_at_trx_commit | 2     |
    +--------------------------------+-------+
    2 rows in set (0.00 sec)
    

    -- 重启数据库后失效

    3.导入完开启binlog

    set sql_log_bin=on
    --恢复sql_log和innodb_flush_log_at_trx_commit 状态
    set sql_log_bin=OFF;set global innodb_flush_log_at_trx_commit=2; show VARIABLES like '%log_bin%';SHOW GLOBAL VARIABLES LIKE 'innodb_flush_log%';
    
    set sql_log_bin=on;set global innodb_flush_log_at_trx_commit=1;  show VARIABLES like '%log_bin%';SHOW GLOBAL VARIABLES LIKE 'innodb_flush_log%';
    
    
  • 相关阅读:
    layout布局
    窗口、easyui-window、easyui-panel、easyui-linkbutton
    FASTJSON
    Insert title here
    Insert title here
    Scala并发编程
    scala中java并发编程
    scala调用外部命令
    scala正则表达式
    scala占位符_的用法
  • 原文地址:https://www.cnblogs.com/gczheng/p/9323461.html
Copyright © 2011-2022 走看看