导入:
如果指定./目录,默认是在data目录下,如果不指定目录,则默认在当前的数据库目录下
load data infile '/home/oracle/1.txt' into table t1 charset gbk fields terminated by ',';
load data infile '/home/oracle/1.txt' into table t1 charset gbk fields terminated by ',' (id,name); --指定导入的列,对于没有导入的列,默认为空
load data infile '/home/oracle/1.txt' into table t1 charset gbk fields terminated by ','
charset gbk; --通过设置charset指定导入数据的字符集 或者在导入之前设置set character_set_database=gbk;
load data
local infile '/home/oracle/1.txt' into table t1 charset gbk fields terminated by ','; --设置local指定从客户端目录导入
load data infile '/home/oracle/1.txt' into table t1 charset gbk fields terminated by ','
ignore 1 lines; --导入的时候忽略第一行
load data infile '/tmp/1.txt' into table t4 charset gbk fields terminated by ',' (id,name,
@tmp); --对于文件中的列多于表列的时候,使用@tmp指定null变量
常用参数含义:
files terminated by:指定分隔符
enclosed by:指定列的包括符,例如files terminated指定的是,而一条数据中又包含,那么就需要使用此参数设置额外的分隔符
escaped b:指定转义符 默认是'\'
lines terminated by:指定换行符,默认是\n windows应该为\r\n
lines starting by:指定每行开始的位置,跳过指定的字符的前缀,如果不包含指定字符,那么这行将被跳过。
导出:
导出的文件都是存放在服务器端
select * from t4 into outfile '/tmp/2.txt'; --默认是以tab分隔
select * from t4 into outfile '/tmp/3.txt' fields terminated by ','
enclosed by '"'; --指定分隔符
[root@mysql1 tmp]# cat 3.txt
"1","a"
"2","b"
"3","c"
"1","a"
"2","b"
"3","c"
"4","d"