Home php教程 php手册 php实现mysql数据库分表分段备份

php实现mysql数据库分表分段备份

Jun 06, 2016 pm 08:03 PM

本文给大家分享的是php实现mysql数据库分卷备份,选择表进行备份,实现单个sql文件及分卷sql导入。有需要的小伙伴可以参考下

分卷导出思路:统计sql语句变量的长度,按1个字符当成1 字节比较,如果大于设定分卷大小,则写入一个sql文件(我也不知道这样统计是否稳当,这也是借鉴其他的人的)。

分卷导入思路:按行读取sql文件,将每一行当作完整的sql语句存到数组再循环执行插入数据库就可以了,,但是在创建表语句分了多行,这个需要单独处理(就这个花了我好长时间的);

$filesize){ //写入文件并跳转 $file='data/'.$table.'-'.$part.'.sql'; file_put_contents($file,$backupdata); echo $file.' 备份完成,程序继续进行!'; $part++; //分段 //表名 //起点 //跳转 sleep(3); echo "<script>location.href='&#63;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.'备份完成!
'; sleep(2); $table_index++; if($table_array[$table_index]){ echo "<script>location.href='&#63;table_index={$table_index}';</script>"; exit; }else{ echo '恭喜你,数据库备份完毕!'; } function get_tables($db){ $tq = mysql_list_tables($db); while($tr = mysql_fetch_row($tq)){ $arrtb[] = $tr[0]; } return $arrtb; } ?>

以上所述就是本文的全部内容了,希望大家能够喜欢。

Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)