Mysql
主页 > 数据库 > Mysql >

MySQL source导入很慢的解决方法

2022-03-06 | 秩名 | 点击:

现在有这样一个需求,内网有一个数据库服务,需要将外网的数据库导入到内网数据库。

将外网的数据库导出sql文件有700MB+,用MySQL自带的source导入很慢,于是就用了如下方法加速导入,亲测很快。

1. 登录MySQL

进入内网服务器,登录mysql,输入密码即可。

1

mysql -u root -p

2. 创建数据库

根据需求创建数据库

1

create database 数据库名;

3. 设置参数

sql_log_bin 关闭二进制日志

autocommit 关闭事务自动提交

1

2

set sql_log_bin=off;

set autocommit=0;

4. 使用数据库

1

use 数据库名;

5. 开启事务

1

start transaction;

6. 导入sql

1

source 文件.sql;

7. 手动提交事务

1

commit;

8. 改回配置

1

2

set sql_log_bin=on;

set autocommit=1;

附mysql加速source导入数据

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;

原文链接:https://www.jb51.net/article/239757.htm
相关文章
最新更新