数据表迁移数据一致性验证,迁移数据一致性验证
数据表迁移数据一致性验证,迁移数据一致性验证
在迁移数据库的时候做一些必要的验证还是很有用的,比如说迁移前后的数据条数是否一致,数据是否一致,这个时候怎么办呢,验证条数还好说,要是验证数据是否一致呢,对于重要的数据当然要每条都不会有差错,随机抽样验证肯定是不行的,万一遗漏了就麻烦了,而且两张表不再同一台服务器上。这个时候该怎么办呢,有一种方法:
上面这种方法是同时想出来的,也还不错,但我觉得还有改进的余地:
- 首先就是不是所有字段,仍然有可能在非主要字段出现different。
- 整体效率比较低
我的想法是这样:
第二种方法的好处就是输出文件会在一定范围缩小,比对方便,但是也有缺点,不能像第一种方法一样直接通过关键字段定位不同数据的位置。
下面是第二种方法效果和的具体代码实现:
'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"; } }

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Redis is an open source, high-performance NoSQL database. Due to its fast read and write speed and rich data structure, it is widely used in cache, queues, distributed locks, etc. However, its application in the field of distributed transactions still needs to be further studied. This article will start from the characteristics of Redis and explore how to use Redis to ensure the consistency and reliability of distributed transactions. 1. Data structure characteristics of Redis Redis supports a wide range of data structures, including strings, lists, hash tables, sets, etc. this

How to implement the consistency and fault-tolerance mechanism of distributed cache in Java. Distributed cache is a commonly used technology in high-concurrency Internet systems. It can improve the performance and scalability of the system. However, distributed caches face consistency and fault tolerance challenges. In this article, we will discuss how to implement distributed cache consistency and fault tolerance in Java and provide specific code examples. 1. Consistency mechanism In a distributed environment, cache consistency is very important. The consistency of distributed cache can be achieved through the following two mechanisms: cache update

How to deal with concurrent database data consistency issues in Go language? When multiple concurrent requests access the database at the same time, data consistency issues may arise. In Go language, we can use transactions and locks to deal with this problem. Below I will introduce in detail how to handle concurrent database data consistency issues in the Go language and give specific code examples. First, we need to use the transaction mechanism of the database. Database transactions provide a mechanism for treating a series of database operations as a whole, either all succeeding or all failing.

Redis is a high-performance in-memory database that is widely used for large-scale data storage and processing. In addition to being used as an independent database, Redis can also be used as a cache layer to improve the access speed of the system. In distributed application scenarios, Redis plays an increasingly important role as a distributed cache. However, in a distributed environment, how to ensure the consistency of the Redis distributed cache is a difficult problem that developers need to face. This article will introduce the method and application examples of Redis to achieve distributed cache consistency. one

Master Distributed Cache Consistency Skills in Java Development With the rapid development of the Internet, most applications are facing the challenges of distributed systems. In order to improve performance and scalability, many applications use distributed cache to cache data. However, the consistency problem of distributed cache has always been a difficult problem faced by developers. This article will introduce some distributed cache consistency techniques in Java development to help developers solve these problems. 1. Background knowledge of distributed caching. Before introducing specific techniques, let us first understand distributed caching.

With the rapid development of Internet applications, distributed architecture has become an important choice for enterprise-level applications. As one of the common caching technologies, Redis also plays an important role. The reliability and consistency of distributed transactions are one of the inevitable topics in architecture design. This article will take Redis as an example to discuss its reliability and consistency comparison in distributed transactions. 1. Common problems with Redis Redis provides fast and efficient access by caching data in memory. But at the same time, it also faces problems such as data loss.

With the development of Internet technology, distributed application systems have become a challenge that programmers must face in their daily work. When dealing with distributed data, ensuring consistency is one of our biggest concerns. At this time, MySql is a favored solution because it can provide most of the functions required by distributed applications. This article will introduce how to use MySql to solve data consistency problems in a distributed environment. What is a distributed transaction? A distributed transaction means that the operation of a transaction involves multiple independent calculations.

Redis is a high-performance, distributed memory database that is widely used in distributed systems. In distributed systems, how to achieve transaction consistency has always been a problem, and the transaction mechanism provided by Redis can help developers solve this problem. This article will introduce how Redis achieves the consistency of distributed transactions and show code examples. 1. Introduction to Redis transaction mechanism Redis provides a transaction mechanism in version 2.0, which uses MULTI, EXEC, WATCH, DISCA
