dongtong1226 2015-06-12 07:08
浏览 52

如何使用带有MySQL的PHP​​从在线服务器到脱机服务器的数据库备份

//Assume Server 1
$conn = mysql_connect("127.0.0.1","root","");

//Assume Server 2
$conn1 = mysql_connect("127.0.0.1","root","");

//Server 1 database
mysql_select_db("db1",$conn);

//Server 2 database
mysql_select_db("db2",$conn1);

//Count number of rows from server 1 -> database -> table (tbl1)
$cnt_rw=mysql_query("select count(*) from db1.tbl1");
$cnt_n=mysql_fetch_array($cnt_rw);  

//Fetch and update row one by one
for($i=0;$i<($cnt_n['count(*)']);$i++)
{
    $one_row=mysql_query("select * from db1.tbl1 limit $i,1");
    while($one_val=mysql_fetch_array($one_row))
    {
        $one=$one_val['one'];
        $two=$one_val['two'];
        $three=$one_val['three'];
    }

    //Already exist means update else insert so am using replace query
    mysql_query("REPLACE INTO db2.tbl2(one,two,three)values('".$one."','".$two."','".$three."')");
    $one=$two=$three='';
}   

This PHP code is working properly but take a long loading time. So I want a simple query or PHP/MySQL code or any idea to get backups from the online server to the offline server.

Online and offline database fields are same.

  • 写回答

2条回答 默认 最新

  • doudong3570 2015-06-12 07:16
    关注

    Since using PHP might not be the best idea if you have large amount of data you could also use command line tools like mysqldump to get a copy of the data and put it on your local machine with the mysql cli command.

    Another option might be special tools like sqlyog which help you migrating data from one server to another.

    评论

报告相同问题?

悬赏问题

  • ¥20 iqoo11 如何下载安装工程模式
  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?