mysql 常用的insert语句:
INSERT INTO `test` (`code_no`, `coupon_price`, `get_mobile`,`get_order_code`, `code_get_time`, `code_use_order_id`, `is_coupon_get`,`goods_info_id`) VALUES ('testdx113', '20',null, NULL, NULL, NULL, '0',4856),(...)...;
但有时为了更快速地插入大批量数据,需要从文本中导入数据或导出数据到文本。
故此研究了一下mysql的批量文本数据导入导出
mysql 批量导出语句
select *
into outfile '导出文件路径(f:\\test.txt)'
lines terminated by '\r\n' ()
from 表名;
其中lines terminated by “\r\n”表示每一行(即每一条记录)用\r\n分隔,\r\n是window系统的换行符。
mysql 批量导入语句
load data local infile '导入文件路径(f:\\test.txt)'
into table 表名(数据字段1,<span style="line-height: 25.2px; font-family: tahoma, arial, 宋体;">数据字段2</span><span style="line-height: 25.2px; font-family: tahoma, arial, 宋体;">,...(需要导入数据的字段,不需要的可以不写));</span>
导入数据:\n代表null
\n testdx113 20 0 4856\n testdx113 20 0 4856
\n testdx113 20 0 4856
\n testdx113 20 0 4856
注意 :
字段之间的分隔和记录(行)之间的分隔默认是\t(即Tab)和\n。但可以改变,如:
FIELDS TERMINATED BY ',' --字段用,进行分隔
LINES TERMINATED BY ';' --记录用; 进行分隔
另外要注意其它操作系统的换行符与windows可能不相同。