檢查mysql遷庫前後的資料記錄數是否一致

來源:互聯網
上載者:User

標籤:指令碼

<?php$old = [‘host‘ => ‘127.0.0.1‘, ‘username‘ => ‘root‘, ‘passwd‘ => ‘‘];$new = [‘host‘ => ‘11.11.11.123‘, ‘username‘ => ‘abc‘, ‘passwd‘ => ‘abc‘];$old_mysqli = @new mysqli($old[‘host‘], $old[‘username‘], $old[‘passwd‘]);if ($old_mysqli->connect_errno) {    echo $old[‘host‘].":Connect failed: ".$old_mysqli->connect_error.PHP_EOL;    exit();}$new_mysqli = @new mysqli($new[‘host‘], $new[‘username‘], $new[‘passwd‘]);if ($new_mysqli->connect_errno) {    echo $new[‘host‘].":Connect failed: ".$new_mysqli->connect_error.PHP_EOL;    exit();}$query = "SHOW DATABASES";$databases = [];if ($result = $old_mysqli->query($query)) {    while ($row = $result->fetch_row()) {        if(!in_array($row[0], [‘information_schema‘, ‘mysql‘, ‘performance_schema‘, ‘test‘])){            $databases[] = $row[0];        }    }}if(!empty($databases)){    foreach($databases as $k => $database){        $old_mysqli->select_db($database);        $select_db_res = $new_mysqli->select_db($database);        if(!$select_db_res){            die($new[‘host‘].‘ database:‘.$database.‘ is not exist‘);        }        $query = "SHOW TABLES";        if ($result = $old_mysqli->query($query)) {            while ($row = $result->fetch_row()) {                $table = $row[0];                $count_query = "SELECT COUNT(*) FROM `$table` WHERE 1=1";                //echo $database.‘:‘.$count_query.PHP_EOL;                if ($old_count_result = $old_mysqli->query($count_query)) {                    while ($row = $old_count_result->fetch_row()) {                        $old_count = $row[0];                        if ($new_count_result = $new_mysqli->query($count_query)) {                            while ($row = $new_count_result->fetch_row()) {                                $new_count = $row[0];                                //echo $database.‘:‘.$table.‘:‘.$old_count.‘:‘.$new_count.PHP_EOL;                                if($new_count != $old_count){                                    echo $old[‘host‘].‘:‘.$database.‘:‘.$table.‘:count:‘.$old_count.PHP_EOL;                                    echo $new[‘host‘].‘:‘.$database.‘:‘.$table.‘:count:‘.$new_count.PHP_EOL.PHP_EOL;                                }                            }                        }else if(!empty($new_mysqli->error)){                            die($new_mysqli->error);                        }                    }                }            }        }    }}$old_mysqli->close();$new_mysqli->close();


檢查mysql遷庫前後的資料記錄數是否一致

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.