Volume export ideas: count the length of SQL statement variables, compare them as 1 byte by 1 character, and write an SQL file if it is greater than the set volume size (I don’t know if this statistics are stable, and this is also a reference to other people).
Volume import ideas: read the sql file by line, store each line as a complete sql statement to the array and then insert it into the database. However, when creating the table statement, it is divided into multiple rows, which needs to be processed separately (it took me a long time to do this);
<?php //Song Zhenghe Please indicate the source when reprintingset_time_limit(0); header('content-type:text/html;charset=utf-8'); mysql_connect('localhost','root','root'); mysql_select_db('test'); $table_array=get_tables('test'); mysql_query('set names utf8'); $filesize=1024*1024*4; $start=$_GET['start']?$_GET['start']:0; $part=$_GET['part']?$_GET['part']:'1'; $table_index=$_GET['table_index']?$_GET['table_index']:'0'; $table=$table_array[$table_index]; $num=200000000;//This number should be large enough, it can be the total number of records$backupdata=''; if($start=='0'){ $query="SHOW CREATE TABLE `{$table}`"; $result = mysql_query($query); $row = mysql_fetch_row($result); $backupdata .= "DROP TABLE IF EXISTS `{$table}`;\n" . $row[1] . ";\n\n"; } $limit=($start=='0')?'':" limit $start,$num "; $query="select * from `{$table}` $limit "; $result=mysql_query($query); $numfields = mysql_num_fields($result); //Statistics of fieldswhile($row=mysql_fetch_row($result)){ $comma = ''; //Storage commas$backupdata_tmp = "INSERT INTO `{$table}` VALUES ("; for($i=0; $i<$numfields; $i++){ $backupdata_tmp .= $comma . "'" . mysql_escape_string($row[$i]) . "'"; $comma = ','; } $backupdata_tmp .= ");\n"; if(strlen($backupdata)+strlen($backupdata_tmp) > $filesize){ //Write to file and jump$file='data/'.$table.'-'.$part.'.sql'; file_put_contents($file,$backupdata); echo $file.'The backup is complete and the program continues! '; $part++; //Segment//Table name//starting point//Jumpsleep(3); echo "<script>='?start={$start}&table_index={$table_index}&part={$part}';</script>"; exit; } $backupdata.=$backupdata_tmp; $start++; } if($backupdata){ $file='data/'.$table.'-'.$part.'.sql'; file_put_contents($file,$backupdata); } echo $table.'Backup is complete! <br />'; sleep(2); $table_index++; if($table_array[$table_index]){ echo "<script>='?table_index={$table_index}';</script>"; exit; }else{ echo 'Congratulations, the database backup is completed! '; } function get_tables($db){ $tq = mysql_list_tables($db); while($tr = mysql_fetch_row($tq)){ $arrtb[] = $tr[0]; } return $arrtb; } ?>
The above is the entire content of this article, I hope you like it.