原文链接:https://www.modb.pro/db/23208?xy

摘要:mysqlimport是MySQL数据库提供的一个命令行程序,可用于数据导入。1.mysqlimport概述

mysqlimport是MySQL数据库提供的一个命令行程序,可用于数据导入。从本质上来说,是LOAD DATA INFILE的命令接口,而且大多数的选项都和LOAD DATA INFILE语法相同。其语法格式如下:
shell>mysqlimport [options] db_name textfilel [textfile2 …]

和LOAD DATA INFILE不同的是,mysqlimport命令可以用来导入多张表。并且通过–use-threads=参数并发地导入不同的文件。这里的并发是指并发导入多个文件,而不是指mysqlimport可以并发地导入一个文件,这是有明显区别的。此外,通常来说并发地对同一张表进行导入,其效果一般都不会比串行的方式好。

参数说明:
–use-threads=# Load files in parallel. The argument is the number of threads to use for loading data.

2.演示2.1导出数据

cd /usr/local/mysql/bin
./mysqldump -uroot -poracle --tab=/data/backup test
使用mysqldump工具导出test库下面所有的表。添加–tab参数表名,导出的每张表的定义输出到一个文件(xxxTAB.sql),每张表的数据输出到另外一个文件(xxxTAB.txt)。

[root@sourcebackup]#cd/usr/local/mysql/bin[root@sourcebin]#./mysqlpump--versionmysqlpumpVer1.0.0Distrib5.7.20,forlinux-glibc2.12(x86_64)[root@sourcebin]#[root@sourcebin]#./mysqldump-uroot-poracle--tab=/data/backuptestmysqldump:[Warning]Usingapasswordonthecommandlineinterfacecanbeinsecure.[root@sourcebin]#[root@sourcemysql]#cd/data/backup/[root@sourcebackup]#lltotal28-rw-r--r--1rootroot1408Mar2017:37BONUS.sql-rw-rw-rw-1mysqlmysql0Mar2017:37BONUS.txt-rw-r--r--1rootroot1400Mar2017:37DEPT.sql-rw-rw-rw-1mysqlmysql80Mar2017:37DEPT.txt-rw-r--r--1rootroot1662Mar2017:37EMP.sql-rw-rw-rw-1mysqlmysql767Mar2017:37EMP.txt-rw-r--r--1rootroot1383Mar2017:37SALGRADE.sql-rw-rw-rw-1mysqlmysql59Mar2017:37SALGRADE.txt[root@sourcebackup]#[root@sourcebackup]#more/data/backup/DEPT.sql--MySQLdump10.13Distrib5.7.20,forlinux-glibc2.12(x86_64)----Host:localhostDatabase:test----------------------------------------------------------Serverversion5.7.20-log/*!40101SET@OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT*/;/*!40101SET@OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS*/;/*!40101SET@OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION*/;/*!40101SETNAMESutf8*/;/*!40103SET@OLD_TIME_ZONE=@@TIME_ZONE*/;/*!40103SETTIME_ZONE='+00:00'*/;/*!40101SET@OLD_SQL_MODE=@@SQL_MODE,SQL_MODE=''*/;/*!40111SET@OLD_SQL_NOTES=@@SQL_NOTES,SQL_NOTES=0*/;----Tablestructurefortable`DEPT`--DROPTABLEIFEXISTS`DEPT`;/*!40101SET@saved_cs_client=@@character_set_client*/;/*!40101SETcharacter_set_client=utf8*/;CREATETABLE`DEPT`(`DEPTNO`int(10)NOTNULL,`DNAME`varchar(14)DEFAULTNULL,`LOC`varchar(13)DEFAULTNULL,PRIMARYKEY(`DEPTNO`))ENGINE=InnoDBDEFAULTCHARSET=latin1;/*!40101SETcharacter_set_client=@saved_cs_client*/;/*!40103SETTIME_ZONE=@OLD_TIME_ZONE*/;/*!40101SETSQL_MODE=@OLD_SQL_MODE*/;/*!40101SETCHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT*/;/*!40101SETCHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS*/;/*!40101SETCOLLATION_CONNECTION=@OLD_COLLATION_CONNECTION*/;/*!40111SETSQL_NOTES=@OLD_SQL_NOTES*/;--Dumpcompletedon2020-03-2017:37:49[root@sourcebackup]#[root@sourcebackup]#moreDEPT.txt10ACCOUNTINGNEWYORK20RESEARCHDALLAS30SALESCHICAGO40OPERATIONSBOSTON[root@sourcebackup]#2.2新建数据库test1,将数据导入到test1库

[root@sourcebackup]#mysql-pEnterpassword:WelcometotheMySQLmonitor.Commandsendwith;or\g.YourMySQLconnectionidis11Serverversion:5.7.20-logMySQLCommunityServer(GPL)Copyright(c)2000,2013,Oracleand/oritsaffiliates.Allrightsreserved.OracleisaregisteredtrademarkofOracleCorporationand/oritsaffiliates.Othernamesmaybetrademarksoftheirrespectiveowners.Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement.root@db17:41:[(none)]>root@db17:41:[(none)]>createdatabasetest1;QueryOK,1rowaffected(0.11sec)root@db17:41:[(none)]>root@db17:41:[(none)]>showdatabases;+--------------------+|Database|+--------------------+|information_schema||mysql||performance_schema||sys||test||test1|+--------------------+6rowsinset(0.00sec)root@db17:41:[(none)]>root@db17:41:[(none)]>root@db17:41:[(none)]>root@db17:41:[(none)]>exitBye[root@sourcebackup]#2.3导入数据2.3.1导入方法1

使用mysql导入定义,使用mysqlimport方法导入数据
create database test1;
mysql -uroot -poracle test1 </data/backup/DEPT.sql
mysqlimport -uroot -poracle --local test1 /data/backup/DEPT.txt

mysqlimport参数说明:
-L, --local Read all files through the client.

[root@sourcebackup]#mysql-uroot-poracletest1</data/backup/DEPT.sql[root@sourcebackup]#[root@sourcebackup]#mysql-pEnterpassword:WelcometotheMySQLmonitor.Commandsendwith;or\g.YourMySQLconnectionidis17Serverversion:5.7.20-logMySQLCommunityServer(GPL)Copyright(c)2000,2013,Oracleand/oritsaffiliates.Allrightsreserved.OracleisaregisteredtrademarkofOracleCorporationand/oritsaffiliates.Othernamesmaybetrademarksoftheirrespectiveowners.Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement.root@db17:43:[(none)]>root@db17:43:[(none)]>USEtest1;Databasechangedroot@db17:43:[test1]>root@db17:43:[test1]>showtables;+-----------------+|Tables_in_test1|+-----------------+|DEPT|+-----------------+1rowinset(0.00sec)root@db17:43:[test1]>root@db17:43:[test1]>select*fromDEPT;Emptyset(0.00sec)root@db17:43:[test1]>root@db17:44:[test1]>exitBye[root@sourcebackup]#[root@sourcebackup]#mysqlimport-uroot-poracle--localtest1/data/backup/DEPT.txttest1.DEPT:Records:4Deleted:0Skipped:0Warnings:0[root@sourcebackup]#[root@sourcebackup]#mysql-ptest1Enterpassword:WelcometotheMySQLmonitor.Commandsendwith;or\g.YourMySQLconnectionidis21Serverversion:5.7.20-logMySQLCommunityServer(GPL)Copyright(c)2000,2013,Oracleand/oritsaffiliates.Allrightsreserved.OracleisaregisteredtrademarkofOracleCorporationand/oritsaffiliates.Othernamesmaybetrademarksoftheirrespectiveowners.Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement.root@db17:46:[test1]>root@db17:46:[test1]>showtables;+-----------------+|Tables_in_test1|+-----------------+|DEPT|+-----------------+1rowinset(0.00sec)root@db17:46:[test1]>root@db17:46:[test1]>select*fromDEPT;+--------+------------+----------+|DEPTNO|DNAME|LOC|+--------+------------+----------+|10|ACCOUNTING|NEWYORK||20|RESEARCH|DALLAS||30|SALES|CHICAGO||40|OPERATIONS|BOSTON|+--------+------------+----------+4rowsinset(0.00sec)root@db17:46:[test1]>2.3.2导入方法2

在mysql命令行执行脚本创建命令,再使用load data local infile … into …加载数据
mysql -p test1
source /data/backup/DEPT.sql
load data local infile ‘/data/backup/DEPT.txt’ into table DEPT;

[root@sourcebackup]#mysql-ptest1Enterpassword:WelcometotheMySQLmonitor.Commandsendwith;or\g.YourMySQLconnectionidis22Serverversion:5.7.20-logMySQLCommunityServer(GPL)Copyright(c)2000,2013,Oracleand/oritsaffiliates.Allrightsreserved.OracleisaregisteredtrademarkofOracleCorporationand/oritsaffiliates.Othernamesmaybetrademarksoftheirrespectiveowners.Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement.root@db17:47:[test1]>root@db17:47:[test1]>DROPTABLEDEPT;QueryOK,0rowsaffected(0.06sec)root@db17:47:[test1]>source/data/backup/DEPT.sqlQueryOK,0rowsaffected(0.00sec)QueryOK,0rowsaffected(0.00sec)QueryOK,0rowsaffected(0.00sec)QueryOK,0rowsaffected(0.00sec)QueryOK,0rowsaffected(0.00sec)QueryOK,0rowsaffected(0.00sec)QueryOK,0rowsaffected,1warning(0.00sec)QueryOK,0rowsaffected(0.00sec)QueryOK,0rowsaffected(0.01sec)QueryOK,0rowsaffected(0.00sec)QueryOK,0rowsaffected(0.00sec)QueryOK,0rowsaffected(0.03sec)QueryOK,0rowsaffected(0.00sec)QueryOK,0rowsaffected(0.00sec)QueryOK,0rowsaffected,1warning(0.00sec)QueryOK,0rowsaffected(0.00sec)QueryOK,0rowsaffected(0.00sec)QueryOK,0rowsaffected(0.00sec)QueryOK,0rowsaffected(0.00sec)root@db17:47:[test1]>root@db17:47:[test1]>root@db17:47:[test1]>showtables;+-----------------+|Tables_in_test1|+-----------------+|DEPT|+-----------------+1rowinset(0.00sec)root@db17:47:[test1]>root@db17:47:[test1]>select*fromDEPT;Emptyset(0.00sec)root@db17:47:[test1]>root@db17:47:[test1]>root@db17:49:[test1]>loaddatalocalinfile'/data/backup/DEPT.txt'intotableDEPT;QueryOK,4rowsaffected(0.01sec)Records:4Deleted:0Skipped:0Warnings:0root@db17:49:[test1]>root@db17:49:[test1]>root@db17:49:[test1]>select*fromDEPT;+--------+------------+----------+|DEPTNO|DNAME|LOC|+--------+------------+----------+|10|ACCOUNTING|NEWYORK||20|RESEARCH|DALLAS||30|SALES|CHICAGO||40|OPERATIONS|BOSTON|+--------+------------+----------+4rowsinset(0.00sec)root@db17:49:[test1]>2.4并行与串行演示2.4.1环境准备

root@db11:28:[(none)]>usetest1Databasechangedroot@db11:28:[test1]>root@db11:28:[test1]>showtables;+-----------------+|Tables_in_test1|+-----------------+|DEPT|+-----------------+1rowsinset(0.00sec)root@db11:28:[test1]>root@db11:31:[test1]>createtablesbtest1(idint(10)unsignedprimarykey,kint(10)unsigned,cchar(120),padchar(60));QueryOK,0rowsaffected(0.05sec)root@db11:32:[test1]>descsbtest1;+-------+------------------+------+-----+---------+-------+|Field|Type|Null|Key|Default|Extra|+-------+------------------+------+-----+---------+-------+|id|int(10)unsigned|NO|PRI|NULL|||k|int(10)unsigned|YES||NULL|||c|char(120)|YES||NULL|||pad|char(60)|YES||NULL||+-------+------------------+------+-----+---------+-------+4rowsinset(0.00sec)root@db11:32:[test1]>root@db11:33:[test1]>createtablesbtest2(idint(10)unsignedprimarykey,kint(10)unsigned,cchar(120),padchar(60));QueryOK,0rowsaffected(0.02sec)root@db11:33:[test1]>root@db11:33:[test1]>descsbtest2;+-------+------------------+------+-----+---------+-------+|Field|Type|Null|Key|Default|Extra|+-------+------------------+------+-----+---------+-------+|id|int(10)unsigned|NO|PRI|NULL|||k|int(10)unsigned|YES||NULL|||c|char(120)|YES||NULL|||pad|char(60)|YES||NULL||+-------+------------------+------+-----+---------+-------+4rowsinset(0.00sec)root@db11:33:[test1]>root@db11:33:[test1]>showtables;+-----------------+|Tables_in_test1|+-----------------+|DEPT||sbtest1||sbtest2|+-----------------+3rowsinset(0.00sec)root@db11:33:[test1]>root@db11:33:[test1]>exitBye[root@source~]#[root@source~]#cd/data/[root@sourcedata]#[root@sourcedata]#lltotal18372drwxr-xr-x2mysqlmysql4096Mar2111:35backupdrwxr-xr-x7mysqlmysql4096Mar2111:19mysql-rw-r--r--1rootroot6264322Mar2111:36sbtest1.txt-rw-r--r--1rootroot6264322Mar2111:36sbtest2.txt[root@sourcedata]#[root@sourcedata]#moresbtest1.txt10qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt20qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt30qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt40qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt50qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt60qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt70qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt80qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt90qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt100qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt110qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt120qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt130qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt140qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt150qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt160qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt170qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt180qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt190qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt200qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt210qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt220qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt230qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt240qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt250qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt260qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt270qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt280qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt290qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt300qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt310qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt320qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt330qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt340qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt350qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt360qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt370qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt380qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt390qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt400qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt410qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt420qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt430qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt440qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt。。。。。。[root@sourcedata]#moresbtest2.txt10qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt20qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt30qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt40qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt50qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt60qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt70qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt80qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt90qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt100qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt110qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt120qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt130qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt140qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt150qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt160qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt170qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt180qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt190qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt200qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt210qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt220qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt230qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt240qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt250qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt260qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt270qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt280qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt290qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt300qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt310qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt320qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt330qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt340qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt350qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt360qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt370qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt380qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt390qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt400qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt410qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt420qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt430qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt440qqqqqqqqqqwwwwwwwwwweeeeeeeeeerrrrrrrrrrtttttttttt。。。。。。2.4.2串行导入

下面演示串行导入2张表数据:
mysqlimport -uroot -poracle test1 /data/sbtest1.txt /data/sbtest2.txt
show full processlist;

窗口1:

[root@sourcedata]#mysqlimport-uroot-poracletest1/data/sbtest1.txt/data/sbtest2.txttest1.sbtest1:Records:100011Deleted:0Skipped:0Warnings:0test1.sbtest2:Records:100011Deleted:0Skipped:0Warnings:0[root@sourcedata]#

窗口2:
如果在上述命令的运行过程中,查看MySQL的数据库线程列表,应该可以看到类似如下内容:

root@db11:38:[(none)]>showfullprocesslist;+----+------+-----------+-------+---------+------+-----------+----------------------------------------------------------------------------+|Id|User|Host|db|Command|Time|State|Info|+----+------+-----------+-------+---------+------+-----------+----------------------------------------------------------------------------+|9|root|localhost|NULL|Query|0|starting|showfullprocesslist||10|root|localhost|test1|Query|1|executing|LOADDATAINFILE'/data/sbtest1.txt'INTOTABLE`sbtest1`IGNORE0LINES|+----+------+-----------+-------+---------+------+-----------+----------------------------------------------------------------------------+2rowsinset(0.00sec)root@db11:38:[(none)]>root@db11:38:[(none)]>showfullprocesslist;+----+------+-----------+-------+---------+------+-----------+----------------------------------------------------------------------------+|Id|User|Host|db|Command|Time|State|Info|+----+------+-----------+-------+---------+------+-----------+----------------------------------------------------------------------------+|9|root|localhost|NULL|Query|0|starting|showfullprocesslist||10|root|localhost|test1|Query|1|executing|LOADDATAINFILE'/data/sbtest2.txt'INTOTABLE`sbtest2`IGNORE0LINES|+----+------+-----------+-------+---------+------+-----------+----------------------------------------------------------------------------+2rowsinset(0.00sec)root@db11:38:[(none)]>

可以看到,mysqlimport每次只有一个线程在导入数据,不加–use-threads=2参数,是串行地导人数据。

2.4.3并发导入

下面通过mysqlimport并发地导入2张表:
mysqlimport -uroot -poracle --use-threads=2 test1 /data/sbtest1.txt /data/sbtest2.txt
show full processlist;

窗口1:

[root@sourcedata]#mysqlimport-uroot-poracle--use-threads=2test1/data/sbtest1.txt/data/sbtest2.txttest1.sbtest1:Records:100011Deleted:0Skipped:0Warnings:0test1.sbtest2:Records:100011Deleted:0Skipped:0Warnings:0

窗口2:
如果在上述命令的运行过程中,查看MySQL的数据库线程列表,应该可以看到类似如下内容:

root@db11:45:[(none)]>showfullprocesslist;+----+------+-----------+-------+---------+------+-----------+----------------------------------------------------------------------------+|Id|User|Host|db|Command|Time|State|Info|+----+------+-----------+-------+---------+------+-----------+----------------------------------------------------------------------------+|9|root|localhost|NULL|Query|0|starting|showfullprocesslist||11|root|localhost|test1|Query|1|executing|LOADDATAINFILE'/data/sbtest1.txt'INTOTABLE`sbtest1`IGNORE0LINES||12|root|localhost|test1|Query|1|executing|LOADDATAINFILE'/data/sbtest2.txt'INTOTABLE`sbtest2`IGNORE0LINES|+----+------+-----------+-------+---------+------+-----------+----------------------------------------------------------------------------+3rowsinset(0.00sec)root@db11:45:[(none)]>

可以看到,加–use-threads=2参数后,mysqlimport实际上是同时执行了两句LOAD DTA INFILE并发地导人数据。