It is still very useful to do some necessary verification when migrating the database, such as the data strips before and after migration Is the number consistent? Is the data consistent? What should I do at this time? It’s okay to verify the number of entries. What if I want to verify whether the data is consistent? Of course, for important data, every entry must be error-free. Random sampling verification is definitely not possible. If you omit it, you will be in trouble, and the two tables are no longer on the same server. What to do at this time? There is a way:
The above method was thought up at the same time and is not bad, but I think there is room for improvement:
My thoughts are this:
The advantage of the second method is that the output file will be reduced within a certain range, making it easy to compare. However, it also has disadvantages. It cannot directly locate the location of different data through key fields like the first method.
The following is the specific code implementation of the effect of the second method:
'localhost', 'port' => '3306', 'user' => 'root', 'pswd' => '123456', 'charset' => 'utf8', 'tables' => array( 'lagou.pos', 'lagou.pos_innodb', ), ); //Verify format if(!$link = mysql_connect($dbinfos['host'].":".$dbinfos['port'],$dbinfos['user'], $dbinfos['pswd'])) { die("connect to [{$host}@{$port}] failed!!"); } if(!mysql_query("set names {$dbinfos['charset']}")) { die("set charset error : ".mysql_error()); } foreach ($dbinfos['tables'] as $table) { if($is_count) { $sql = "select count(*) as nums from {$table}"; $ret = mysql_query($sql); if(!$ret) { die("error : ".mysql_error()); } $ret = mysql_fetch_array($ret, MYSQL_ASSOC); echo "{$table} : {$ret['nums']}n"; } if($is_md5) { $path = $is_md5.DIRECTORY_SEPARATOR.$table; $sql = "select * from {$table}"; $ret = mysql_query($sql); $flag = 0; $fields = ''; while ($_ret = mysql_fetch_array($ret, MYSQL_NUM)) { $flag; while($_ret) { $fields .= array_pop($_ret); } if($flag % $conbine_num == 0) { file_put_contents($path, md5($fields)."n", FILE_APPEND); $fields = ''; } } if($flag % $conbine_num != 0 && $flag > 0) { file_put_contents($path, md5($fields)."n", FILE_APPEND); } echo "save to file info : ".realpath($path)."n"; } }