Now there is such a demand. There is a database service on the intranet, and the database on the external network needs to be imported into the intranet database.
The sql file exported from the external network database is 700MB. It is very slow to import it using the source that comes with MySQL, so I used the following method to speed up the import. It is very fast in personal testing.
Enter the intranet server, log in to mysql, and enter the password.
mysql -u root -p
Create database according to requirements
create database 数据库名;
sql_log_bin Close binary log
autocommit Close Automatic transaction submission
set sql_log_bin=off; set autocommit=0;
use 数据库名;
start transaction;
source 文件.sql;
commit;
set sql_log_bin=on; set autocommit=1;
# 进入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;
The above is the detailed content of How to solve the problem that MySQL source import is very slow?. For more information, please follow other related articles on the PHP Chinese website!