一、查询表结构
mysql> desc province;
+-----------+-------------+------+-----+---------+----------------+
| Field???? | Type??????? | Null | Key | Default | Extra????????? |
+-----------+-------------+------+-----+---------+----------------+
| id??????? | int(11)???? | NO?? | PRI | NULL??? | auto_increment |
| name????? | varchar(32) | NO?? |???? | NULL??? |??????????????? |
| countryId | int(11)???? | YES? | MUL | NULL??? |??????????????? |
+-----------+-------------+------+-----+---------+----------------+
二、表中数据导出为文本文件(.txt)
select id,name,countryId into outfile"d:/data_out.txt" lines terminated by "\r\n" from province;
?导出结果:
1??? 北京??? 1
2??? 上海??? 1
3??? 天津??? 1
4??? 重庆??? 1
5??? 黑龙江??? 1
6??? 吉林??? 1
7??? 辽宁??? 1
……
三、文本文件导入数据库
load data local infile "d:/data_out.txt" into table t_province(id,name);
?导入结果:
mysql> select * from t_province;
+----+--------+
| id | name?? |
+----+--------+
|? 1 | 北京?? |
|? 2 | 上海?? |
|? 3 | 天津?? |
|? 4 | 重庆?? |
|? 5 | 黑龙江 |