目录
一.导出数据
1.1把数据导出到输出文件
通常制表符用于分隔同一行中的值,换行符用于行与行之间的分隔。
into outfile
select * from film into outfile 'd:film.txt';
select * from film into outfile 'd:film.txt'
fields terminated by ',' enclosed by "";
以逗号分隔,用双引号括起数据。
select * from film into outfile 'd:film.txt'
lines starting by '*' terminated by '$';
行以*开始,以$结束。
1.2把数据导出到转储文件
转储文件中的数据全部在一行中,没有任何分隔符。
into dumpfile
select picture from staff where
staff_id = 1 into dumpfile 'd:p1.png' ;
把staff_id=1的员工照片导出到p1.png转储文件中。
二.导入数据
2.1使用MySQL实用程序
load data
load data infile "d:xxx.txt" into table <table_name>;
source
导sql文件
source <d:xxx.sql>
mysql命名
mysql -h localhost -u -p < "d:xxx.sql"
2.2使用mysqlimport实用程序
shell>mysqlimport [options] <database_name> <file_name>
以下是[options]的内容
导入product_info
CREATE TABLE `product_info`(
`product_id` bigint,
`product_name` string,
`extend_info` string)
row format delimited fields terminated by '\t';
load data local inpath '/.../product_info.txt'
into table product_info;