关于insert 数据导入表中问题

t240034137 2010-11-12 11:12:09
1.insert into tables value(xxx1,xxxx,xxx,.....);insert into tables value(xxx2,xxxx,xxx,.....);insert into tables value(xxx3,xxxx,xxx,.....);......

insert into tables select (xxx1,xxxx,xxx,.....)union all select (xxx2,xxxx,xxx,.....)union all select (xxx3,xxxx,xxx,.....)union all.....

数据导入表中谁快点?(百万数据)

2.每次执行一条insert into tables 的时候先导入数据 然后在建立索引!还是一条SQL全部执行完成后 在执行建立索引?(如果这个问题解决上面的问题就知道了)
...全文
117 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
amani11 2010-11-12
  • 打赏
  • 举报
回复
一次插入百万级别数据量

可以考虑用
load data local infile ……
在-云端 2010-11-12
  • 打赏
  • 举报
回复
如果你能把所有数据都拆份开来一条条插入,这样效率是更高的!
但是百w级的数据你这样做的话效率反倒低了,没insert into select 来的方便快捷!
zhaojunwww 2010-11-12
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 t240034137 的回复:]
引用 4 楼 zhaojunwww 的回复:

索引是在建表的时候就建立的 导出数据表备份 用的时候导入就可以了

表中的一些字段是建立索引的!在导入数据的时候 不需要在这些字段上加入吗?
[/Quote]
如果建表的时候就有索引 再导入肯定不需要在建立索引了 难道你没有导入过数据表?
t240034137 2010-11-12
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 zhaojunwww 的回复:]

索引是在建表的时候就建立的 导出数据表备份 用的时候导入就可以了
[/Quote]
表中的一些字段是建立索引的!在导入数据的时候 不需要在这些字段上加入吗?
lazysmile 2010-11-12
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 ihefe 的回复:]
一条一条来。 写好存储过程。事务回滚
[/Quote
现在用mysql基本都是MyISAM,Innodb貌似不多见,这样事我觉得不需要考虑事务性。
zhaojunwww 2010-11-12
  • 打赏
  • 举报
回复
索引是在建表的时候就建立的 导出数据表备份 用的时候导入就可以了
t240034137 2010-11-12
  • 打赏
  • 举报
回复
我说的是
$sql="insert into tables value(xxx1,xxxx,xxx,.....);insert into tables value(xxx2,xxxx,xxx,.....);insert into tables value(xxx3,xxxx,xxx,.....);......";



$sql="insert into tables select (xxx1,xxxx,xxx,.....)union all select (xxx2,xxxx,xxx,.....)union all select (xxx3,xxxx,xxx,.....)union all.....";


数据导入表中谁快点?(百万数据)
lazysmile 2010-11-12
  • 打赏
  • 举报
回复
导入最好不要一条一条的insert,很慢。
ihefe 2010-11-12
  • 打赏
  • 举报
回复
一条一条来。 写好存储过程。事务回滚
t240034137 2010-11-12
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 heyc1998 的回复:]

如果你能把所有数据都拆份开来一条条插入,这样效率是更高的!
但是百w级的数据你这样做的话效率反倒低了,没insert into select 来的方便快捷!
[/Quote]
但是这样就会超时!不适合大量导入!

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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