时间:2021-07-01 10:21:17 帮助过:3人阅读
1 php 2 header("content-type:text/html;charset=utf-8"); 3 error_reporting(E_ALL); 4 set_time_limit(0); 5 $file='./test.sql'; 6 $data=file($file); 7 8 echo ""; 9 //print_r($data); 10 $data_new=array(); 11 $tmp=array(); 12 foreach ($data as $line) { 13 14 $line=trim($line); 15 if(strlen($line)==0){ 16 continue; 17 } 18 if(substr($line,0,2)=='--'){ 19 continue; 20 } 21 if(substr($line,0,2)=='/*'){ 22 continue; 23 } 24 $tmp[]=$line; 25 if(substr($line,-1)==';'){ 26 $query=implode('',$tmp); 27 $tmp=array(); 28 $data_new[]=$query; 29 } 30 31 } 32 33 34 35 $mysqli=new mysqli('localhost','root','root','test'); 36 if($mysqli->connect_errno){ 37 exit('数据库连接失败!'); 38 } 39 $mysqli->query("set names utf8"); 40 41 $error=array(); 42 foreach($data_new as $sql){ 43 $mysqli->query($sql); 44 $r=$mysqli->error; 45 if($r) $error[]=$r; 46 } 47 print_r($r); 48 49 50 /* 51 52 53 mysql>ALTER TABLE tbl2 DISABLE KEYS; 54 Query OK, 0 rows affected (0.00 sec) 55 56 mysql>INSERT INTO tbl2 SELECT * FROM tbl1; 57 Query OK, 2000000 row affected (36.30 sec) 58 Records: 2000000 Duplicates: 0 Warnings: 0 59 60 mysql>ALTER TABLE tbl2 ENABLE KEYS; 61 Query OK, 0 rows affected (44.55 sec) 62 63 64 */适用情况:phpmyadmin导出的sql文件过大,无法导入到线上phpmyadmin中
把该程序和sql文件上传到空间中,用完后删除即可。
http://www.bkjia.com/PHPjc/1014830.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1014830.htmlTechArticlephp 在线 mysql 大数据导入程序,mysql数据导入 1 ? php 2 header ("content-type:text/html;charset=utf-8" ); 3 error_reporting ( E_ALL ); 4 set_time_limit (0 ); 5 $file =...