mysql根据条件插入数据

INSERT INTO tablename [(columns...)] SELECT 4,4 from dual WHERE not exists (select * from tablename where ...);

(columns...)要插入数据的列集合 省略时按表结构顺序匹配
根据条件插入数据

 

 导入数据

mysql.exe -uroot -hlocalhost uams < c:\acts.xml

数据快速导入

load data infile ‘/tmp/tab_a.txt’ into table tab_a fields terminated by ‘,’ optionally enclosed by ‘”‘ lines terminated by ‘\n’ (id,name,gmt_create) set gmt_modified=gmt_create;

fields terminated by ‘,’ 是指字段间以逗号分隔;

optionally enclosed by ‘”‘表示:字符型日期型的字段会加””。如果是ENCLOSED BY ‘”‘的话,所有的字段都会加”, ENCLOSED BY描述的是字段的括起字符。比方以引号括起每一个字段。

Load时还可以加上括号指定字段,比如文件里没有gmt_modified值,还可以使用set来解决。

2)当要忽视原来表中的数据时,可以用replace 或者ignore



posted @ 2011-06-14 17:17  风来君  阅读(2397)  评论(0)    收藏  举报