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%';