load data infile方式数据无法正确导入的问题

lingxaiyidu 2012-08-09 05:49:29
请教大家
看资料上讲到load data方式导入数据速度很快 于是我测试了下
但是我用 select * into outfile 导出数据
load data infile 方式导入数据 但是数据导入时 报错 插入不进去

导入 :
mysql> SELECT * INTO OUTFILE '/usr/local/mysql/var/emp.txt' fields terminated by ',' optionally enclosed by "'" lines terminated by ';\n' from emp;
Query OK, 7 rows affected (0.00 sec)
查看导出文件:
[*@** ]$more emp.txt
1,'a','dba','2012-01-01 12:12:12',12.23;
2,'b','dba','2012-02-02 22:22:22',98.23;
3,'d','pm','2008-02-02 10:22:22',198.23;
4,'e','dev','2010-10-02 08:22:30',108.23;
5,'f','sell','2011-10-02 11:22:30',360.23;
1001,'we','manager','2001-11-08 09:21:30',8880.23;
20001,'dd','caiwu','2009-08-12 14:21:30',80.23;

导入:
mysql> load data infile '/usr/local/mysql/var/emp.txt' into table emp;
Query OK, 7 rows affected, 35 warnings (0.00 sec)
Records: 7 Deleted: 0 Skipped: 0 Warnings: 35
报错及报错信息:
mysql> show warnings;
+---------+------+--------------------------------------------+
| Level | Code | Message |
+---------+------+--------------------------------------------+
| Warning | 1265 | Data truncated for column 'empno' at row 1 |
| Warning | 1261 | Row 1 doesn't contain data for all columns |
| Warning | 1261 | Row 1 doesn't contain data for all columns |
| Warning | 1261 | Row 1 doesn't contain data for all columns |
| Warning | 1261 | Row 1 doesn't contain data for all columns |
| Warning | 1265 | Data truncated for column 'empno' at row 2 |
| Warning | 1261 | Row 2 doesn't contain data for all columns |
| Warning | 1261 | Row 2 doesn't contain data for all columns |
| Warning | 1261 | Row 2 doesn't contain data for all columns |
| Warning | 1261 | Row 2 doesn't contain data for all columns |
| Warning | 1265 | Data truncated for column 'empno' at row 3 |
| Warning | 1261 | Row 3 doesn't contain data for all columns |
| Warning | 1261 | Row 3 doesn't contain data for all columns |
| Warning | 1261 | Row 3 doesn't contain data for all columns |
| Warning | 1261 | Row 3 doesn't contain data for all columns |
| Warning | 1265 | Data truncated for column 'empno' at row 4 |
| Warning | 1261 | Row 4 doesn't contain data for all columns |
| Warning | 1261 | Row 4 doesn't contain data for all columns |
| Warning | 1261 | Row 4 doesn't contain data for all columns |
| Warning | 1261 | Row 4 doesn't contain data for all columns |
| Warning | 1265 | Data truncated for column 'empno' at row 5 |
| Warning | 1261 | Row 5 doesn't contain data for all columns |
| Warning | 1261 | Row 5 doesn't contain data for all columns |
| Warning | 1261 | Row 5 doesn't contain data for all columns |
| Warning | 1261 | Row 5 doesn't contain data for all columns |
| Warning | 1265 | Data truncated for column 'empno' at row 6 |
| Warning | 1261 | Row 6 doesn't contain data for all columns |
| Warning | 1261 | Row 6 doesn't contain data for all columns |
| Warning | 1261 | Row 6 doesn't contain data for all columns |
| Warning | 1261 | Row 6 doesn't contain data for all columns |
| Warning | 1265 | Data truncated for column 'empno' at row 7 |
| Warning | 1261 | Row 7 doesn't contain data for all columns |
| Warning | 1261 | Row 7 doesn't contain data for all columns |
| Warning | 1261 | Row 7 doesn't contain data for all columns |
| Warning | 1261 | Row 7 doesn't contain data for all columns |
+---------+------+--------------------------------------------+
35 rows in set (0.01 sec)
查看表导入的数据:
mysql> SELECT * FROM emp;
+-------+-------+------+----------+------+
| empno | ename | job | hiredate | sal |
+-------+-------+------+----------+------+
| 1 | NULL | NULL | NULL | NULL |
| 2 | NULL | NULL | NULL | NULL |
| 3 | NULL | NULL | NULL | NULL |
| 4 | NULL | NULL | NULL | NULL |
| 5 | NULL | NULL | NULL | NULL |
| 1001 | NULL | NULL | NULL | NULL |
| 20001 | NULL | NULL | NULL | NULL |
+-------+-------+------+----------+------+
7 rows in set (0.00 sec)
一条记录都没有导入进来
请教高手指点下 这是怎么回事啊
感谢
...全文
919 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
lingxaiyidu 2012-08-10
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

把你的乱七八糟的都去掉

用一下语句
mysql> SELECT * INTO OUTFILE '/usr/local/mysql/var/emp.txt' from emp;
mysql> load data infile '/usr/local/mysql/var/emp.txt' into table emp;
[/Quote]

不加限定设置
导入导出也正常

我原以为系统会不识别呢
好用
感谢
lingxaiyidu 2012-08-10
  • 打赏
  • 举报
回复
修改过了
如下:
mysql> load data infile '/usr/local/mysql/var/emp.txt' into table emp fields terminated by ',' optionally enclosed by "'" lines terminated by ';\n';
插入数据正确
感谢大家的帮助

wwwwb 2012-08-10
  • 打赏
  • 举报
回复

fields terminated by ',' optionally enclosed by "'" lines terminated by ';\n' from emp;
加入到LOAD DATA INIFILE中
ACMAIN_CHM 2012-08-09
  • 打赏
  • 举报
回复
你在导出的时候使用了限定设置,但在导入的时候并没有说明啊。

SELECT * INTO OUTFILE '/usr/local/mysql/var/emp.txt' fields terminated by ',' optionally enclosed by "'" lines terminated by ';\n' from emp;
rucypli 2012-08-09
  • 打赏
  • 举报
回复
把你的乱七八糟的都去掉

用一下语句
mysql> SELECT * INTO OUTFILE '/usr/local/mysql/var/emp.txt' from emp;
mysql> load data infile '/usr/local/mysql/var/emp.txt' into table emp;

56,687

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧