Data table migration Data Consistency validation

Source: Internet
Author: User
Tags file info
In the migration of the database to do some necessary validation is still useful, such as before and after the migration of data lines are consistent, the data is consistent, how to do this time, verify the number of bars is good to say, if the validation data is consistent, for the important data of course there will be no error, random sampling verification is certainly not, In case the omission is troublesome, and the two tables are no longer on the same server. What to do at this time, there is a way:

    1. Select several important fields from the table, such as a, B, and C, using these fields as the ruler of the alignment.
    2. Export these three fields of each data from the original table to a file F1.
    3. These three fields of each data are everywhere in the destination table into file F2.
    4. Is the same as each data in the file F1, F2 file.
    5. Come to the conclusion

The above method is at the same time to think out, but also good, but I think there is room for improvement:

    • The first is not all fields, and it is still possible to different in non-primary fields.
    • Low overall efficiency

My idea is this:

    1. concatenation of every n data in a table (directly connected, n values depend on the amount of data per data).
    2. Calculates the MD5 value of this n data, and adds it to the file F1 until all data is evaluated.
    3. The same is true for the destination table, where the recorded file is F2.
    4. Compared to the file F1, F2 file MD5 value, if consistent, OK, success.
    5. If not consistent, fall from above to each MD5 value, find the article M inconsistent.
    6. It is concluded that the inconsistent data between m* (n-1) +1 ~ m*n can be selected again for positioning.

The advantage of the second approach is that the output file will be reduced to a certain extent, more convenient, but there are shortcomings, not as the first method directly through the key field to locate different data location.

Here is the second method effect and the specific code implementation:

  ' localhost ', ' port ' = ' 3306 ', ' user ' + ' root ', ' pswd ' = ' 123456 ', ' charset ' = ' utf8 ', ' tables ' = = Array (' L Agou.pos ', ' Lagou.pos_innodb ',),);//Verify the 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 ($s QL); 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 ";}}

  

The above describes the data table migration data consistency validation, including aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.