Data table migration data consistency verification, migration data consistency verification_PHP tutorial

WBOY
Release: 2016-07-13 09:56:18
Original
1208 people have browsed it

Data table migration data consistency verification, migration data consistency verification

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:

  • First of all, not all fields may appear different in non-main fields.
  • The overall efficiency is relatively low

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:

Data table migration data consistency verification, migration data consistency verification_PHP tutorial '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"; } }

 

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/989413.htmlTechArticleData table migration data consistency verification, migration data consistency verification. Do some necessary verifications when migrating the database? Very useful, for example, whether the number of data items before and after migration is the same...
Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!