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%';
    
    
  • 相关阅读:
    JS基础类型和引用类型
    ul的margin撑不开想要的距离的办法
    html中的列表
    BEM的命名规则
    意义模糊的函数签名……文档注释
    最基础,新手入门第一段代码
    Cookie的使用
    用servlet校验密码2
    用servlet进行用户名和密码校验
    登录页面
  • 原文地址:https://www.cnblogs.com/gczheng/p/9323461.html
Copyright © 2011-2022 走看看