Php

MySQL:如何在不導出/導入的情況下將數據庫從一台伺服器複製到另一台伺服器

  • February 23, 2015

我可以訪問兩個不同的 Windows 系統。一個系統上有一個 MySQL 數據庫,我想將其複製到另一個系統。請注意,在該數據庫可用的第一個系統上,我沒有用於數據庫訪問的使用者名和密碼。我已經搜尋過這個問題,但沒有找到與我相關的答案

我可以幫你

從第一台機器複製所有文件駐留在C:\wamp\bin\mysql\mysql5.6.12\data

並將其複製到同一路徑中的新加工中。

希望能幫助到你

試試這個數據遷移器

<?php 
/**
* Data Migrator Merger is for merging the data/records of two database of completely same or similar schema.
* 
* @author Nitesh Apte
*/

class DataMigratorMreger {

   private $conn;
   private $sourceDB;
   private $destinationDB;


   public function __construct() {
       $this->conn = mysql_connect("localhost", "root", "");
   }

   public function mergeData($oldSchema, $newSchema, $reverse = FALSE) {
       mysql_query("SET FOREIGN_KEY_CHECKS = 0");

       if($reverse) {
           $this->destinationDB = $oldSchema;
           $this->sourceDB = $newSchema;
       } else {
           $this->destinationDB = $newSchema;
           $this->sourceDB = $oldSchema;
       }

       mysql_query("use ".$oldSchema);

       $tables = $this->getAssoc("show tables");

       for($i=0;$i<count($tables);$i++) {

           /* Disable this in case you want to merge the data */
           $trun = "TRUNCATE $this->destinationDB.".$tables[$i]['Tables_in_'.$this->sourceDB];
           mysql_query($trun);

           $values = $this->getAssoc("describe ".$tables[$i]['Tables_in_'.$oldSchema]);

           // put $j=1 in case of merging. Generally, first column is auto incremented id
           for($j=0;$j<count($values);$j++) {
               $val[$i][] =  $values[$j]['Field'];
           }

           $field = implode(',', $val[$i]);

           $sql = "INSERT INTO $this->destinationDB.".$tables[$i]['Tables_in_'.$oldSchema]." ($field) SELECT ".$field." FROM $this->sourceDB.".$tables[$i]['Tables_in_'.$oldSchema];

           mysql_query($sql);
       }

       mysql_query("SET FOREIGN_KEY_CHECKS = 1");
   }

   public function getAssoc($queryString) {

       $rs = mysql_query($queryString, $this->conn);

       while($rw = @mysql_fetch_array($rs, MYSQL_ASSOC)){
           $values[] = $rw;
       }
       return $values;
   }
}
?>

引用自:https://dba.stackexchange.com/questions/60072