Home  >  Article  >  Backend Development  >  百万的数据要怎么插入数据库?

百万的数据要怎么插入数据库?

WBOY
WBOYOriginal
2016-06-23 13:57:44981browse

表中有百万条左右的数据,一次姓取出插入,好像不起作用,只能插入几千条程序就不运行了,能不能读取一条,插入一条呢?要怎么操作?


回复讨论(解决方案)

在控制台中
insert into newtbl select * from oldtab

这种数据搬迁的工作又不是经常做,时间长点就等一下呗 

我是用insert into 是从一个表取出插入另一个表,好像运行到两三千条,程序就停止了。

在控制台里运行的吗?

不是控制台,是php文件里,因为是不同数据库。已经将max_execution_time 设置为0

贴出你的代码!

程序虽然504 Gateway Time-out,担数据好像还是在插入呢,只要以插入数据库就行了。先不管了。

贴出你的代码!



代码:
 while($mssql_row = mssql_fetch_array($rs)) 


$fTMID = $mssql_row[0];

$sql = "insert into Flow01(fZTDM,) values ('$fZTDM',)";
mysql_query('set names gbk');
mysql_query($sql);


要怎么进行优化?

mysql_query('set names gbk');while($mssql_row = mssql_fetch_array($rs))  {   $fTMID = $mssql_row[0];  $sql = "insert into Flow01(fZTDM,) values ('$fZTDM',)";  mysql_query($sql);	  echo ' ';} 

基本无优化的余地

页面超时了,解决页面超时就可以了,我前面采用的方法是,执行1000条 然后再跳转到这个页面继续执行
直到全部执行完成

嗯,还是谢谢你的热情回答。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn