现在有这样一个需求,内网有一个数据库服务,需要将外网的数据库导入到内网数据库。
将外网的数据库导出sql文件有700MB+,用MySQL自带的source导入很慢,于是就用了如下方法加速导入,亲测很快。
进入内网服务器,登录mysql,输入密码即可。
1 |
mysql -u root -p |
根据需求创建数据库
1 |
create database 数据库名; |
sql_log_bin 关闭二进制日志
autocommit 关闭事务自动提交
1 2 |
set sql_log_bin=off; set autocommit=0; |
1 |
use 数据库名; |
1 |
start transaction; |
1 |
source 文件.sql; |
1 |
commit; |
1 2 |
set sql_log_bin=on; set autocommit=1; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
# 进入mysql中执行如下 SET GLOBAL foreign_key_checks=0; SET GLOBAL unique_checks=0; SET GLOBAL innodb_flush_log_at_trx_commit=0; SET GLOBAL sync_binlog=0;
-- 你的sql语句1 -- 你的sql语句2 -- 你的sql语句3
SET GLOBAL foreign_key_checks=1; SET GLOBAL unique_checks=1; SET GLOBAL innodb_flush_log_at_trx_commit=1; SET GLOBAL sync_binlog=1; |