数据表迁移数据一致性验证,迁移数据一致性验证_PHP教程

WBOY
Freigeben: 2016-07-13 09:56:18
Original
1153 Leute haben es durchsucht

数据表迁移数据一致性验证,迁移数据一致性验证

  在迁移数据库的时候做一些必要的验证还是很有用的,比如说迁移前后的数据条数是否一致,数据是否一致,这个时候怎么办呢,验证条数还好说,要是验证数据是否一致呢,对于重要的数据当然要每条都不会有差错,随机抽样验证肯定是不行的,万一遗漏了就麻烦了,而且两张表不再同一台服务器上。这个时候该怎么办呢,有一种方法:

  上面这种方法是同时想出来的,也还不错,但我觉得还有改进的余地:

  • 首先就是不是所有字段,仍然有可能在非主要字段出现different。
  • 整体效率比较低

  我的想法是这样:

  第二种方法的好处就是输出文件会在一定范围缩小,比对方便,但是也有缺点,不能像第一种方法一样直接通过关键字段定位不同数据的位置。

  下面是第二种方法效果和的具体代码实现:

数据表迁移数据一致性验证,迁移数据一致性验证_PHP教程 'localhost', 'port' => '3306', 'user' => 'root', 'pswd' => '123456', 'charset' => 'utf8', 'tables' => array( 'lagou.pos', 'lagou.pos_innodb', ), ); //验证格式 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.htmlTechArticle数据表迁移数据一致性验证,迁移数据一致性验证 在迁移数据库的时候做一些必要的验证还是很有用的,比如说迁移前后的数据条数是否一...
Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!