Mafiree logo
  • About
  • Services
  • Blogs
  • Careers
  • Products
    • orbit logo Orbit
    • streamer logo Xstreami
  • Contact
Schedule a Call
Menu
  • About
  • Services
  • Blogs
  • Careers
  • Products
    • orbit logo Orbit
    • streamer logo Xstreami
  • Contact
  • Schedule a Call
Database
Database Database Managed Services
MySQL MySQL
MySQL Consulting Services
MySQL Migration Services
MySQL Optimization & Query Tuning
MySQL Database Administration
MySQL Backup & Recovery
MySQL Security & Maintenance
MySQL Cloud Services (AWS RDS, Aurora, Google Cloud SQL, Azure)
MySQL for Ecommerce
MySQL High Availability & Replication
MongoDB MongoDB
MongoDB Consulting Services
MongoDB Migration Services
MongoDB Optimization & Query Tuning
MongoDB Database Administration
MongoDB Backup & Recovery
MongoDB Security & Maintenance
MongoDB Cloud (Atlas)
MongoDB Solutions by Industry
MongoDB High Availability & Replication
PostgreSQL PostgreSQL
PostgreSQL Consulting
PostgreSQL Migration & Upgrades
Performance Tuning & Query Optimization
PostgreSQL Administration & Managed Services
High Availability, Clustering & Replication
PostgreSQL Backup, Recovery & Disaster Planning
PostgreSQL Security, Compliance & Auditing
PostgreSQL for Analytics & Data Warehousing
PostgreSQL on Cloud & Containers
PostgreSQL Extensions & Open-Source Integrations
PostgreSQL for Every Industry
SQL Server MSSQL
MSSQL Consulting Services
MSSQL Migration Services
MSSQL Optimization & Query Tuning Services
MSSQL Database Administration Services
MSSQL Backup & Recovery Services
MSSQL High Availability & Replication Services
MSSQL Security & Compliance Services
MSSQL Performance Monitoring & Health Checks
MSSQL Solutions by Industry
Aerospike Aerospike
Aerospike Consulting Services
Aerospike Migration Services
Aerospike Performance Optimization & Tuning
Aerospike Database Administration
Aerospike Backup & Recovery
Aerospike High Availability
Aerospike Cloud & Hybrid Deployments
Aerospike for Real-Time Applications (AdTech, FinTech, Retail, IoT)
Analytics DB
Analytics DB Analytics DB Services
Clickhouse Clickhouse
ClickHouse Consulting Services
ClickHouse Migration Services
ClickHouse Optimization & Query Tuning
ClickHouse Database Administration
ClickHouse Backup & Recovery
ClickHouse Security & Maintenance
ClickHouse Cloud Services (ClickHouse Cloud, AWS, GCP, Azure)
ClickHouse Solutions by Industry
ClickHouse High Availability & Replication
TiDB TiDB
TiDB Consulting & Architecture Planning
TiDB Administration & Maintenance
TiDB Security and Privacy Maintenance
TiDB Performance & Query Optimization
TiDB Migration Services
TiDB Backup & Disaster Recovery
TiDB High Availability Solutions
TiDB Solutions by Industry
TiDB Cloud Services
ScyllaDB ScyllaDB
ScyllaDB Consulting & Architecture Planning
ScyllaDB Administration & Maintenance
ScyllaDB Security and Privacy Maintenance
ScyllaDB Performance & Query Optimization
ScyllaDB Migration Services
ScyllaDB Backup & Disaster Recovery
ScyllaDB High Availability Solutions
ScyllaDB Solutions by Industry
ScyllaDB Cloud Services
DevOps
DevOps DevOps Services
Version Control Version Control
Kubernetes Kubernetes
Infrastructure Infrastructure Management
Web Servers Web Servers
Networking
Networking Networking Services
Basic Basic
Advanced Advanced
MySQL MySQL
MongoDB MongoDB
PostgreSQL PostgreSQL
MSSQL MSSQL
Aerospike Aerospike
Clickhouse Clickhouse
TiDB TiDB
ScyllaDB ScyllaDB
Version Control Version Control
Kubernetes Kubernetes
Infrastructure Infrastructure Management
Web Servers Web Servers
Basic Basic
Advanced Advanced
MySQL Consulting Services
MySQL Migration Services
MySQL Optimization & Query Tuning
MySQL Database Administration
MySQL Backup & Recovery
MySQL Security & Maintenance
MySQL Cloud Services (AWS RDS, Aurora, Google Cloud SQL, Azure)
MySQL for Ecommerce
MySQL High Availability & Replication
MongoDB Consulting Services
MongoDB Migration Services
MongoDB Optimization & Query Tuning
MongoDB Database Administration
MongoDB Backup & Recovery
MongoDB Security & Maintenance
MongoDB Cloud (Atlas)
MongoDB Solutions by Industry
MongoDB High Availability & Replication
PostgreSQL Consulting
PostgreSQL Migration & Upgrades
Performance Tuning & Query Optimization
PostgreSQL Administration & Managed Services
High Availability, Clustering & Replication
PostgreSQL Backup, Recovery & Disaster Planning
PostgreSQL Security, Compliance & Auditing
PostgreSQL for Analytics & Data Warehousing
PostgreSQL on Cloud & Containers
PostgreSQL Extensions & Open-Source Integrations
PostgreSQL for Every Industry
MSSQL Consulting Services
MSSQL Migration Services
MSSQL Optimization & Query Tuning Services
MSSQL Database Administration Services
MSSQL Backup & Recovery Services
MSSQL High Availability & Replication Services
MSSQL Security & Compliance Services
MSSQL Performance Monitoring & Health Checks
MSSQL Solutions by Industry
Aerospike Consulting Services
Aerospike Migration Services
Aerospike Performance Optimization & Tuning
Aerospike Database Administration
Aerospike Backup & Recovery
Aerospike High Availability
Aerospike Cloud & Hybrid Deployments
Aerospike for Real-Time Applications (AdTech, FinTech, Retail, IoT)
ClickHouse Consulting Services
ClickHouse Migration Services
ClickHouse Optimization & Query Tuning
ClickHouse Database Administration
ClickHouse Backup & Recovery
ClickHouse Security & Maintenance
ClickHouse Cloud Services (ClickHouse Cloud, AWS, GCP, Azure)
ClickHouse Solutions by Industry
ClickHouse High Availability & Replication
TiDB Consulting & Architecture Planning
TiDB Administration & Maintenance
TiDB Security and Privacy Maintenance
TiDB Performance & Query Optimization
TiDB Migration Services
TiDB Backup & Disaster Recovery
TiDB High Availability Solutions
TiDB Solutions by Industry
TiDB Cloud Services
ScyllaDB Consulting & Architecture Planning
ScyllaDB Administration & Maintenance
ScyllaDB Security and Privacy Maintenance
ScyllaDB Performance & Query Optimization
ScyllaDB Migration Services
ScyllaDB Backup & Disaster Recovery
ScyllaDB High Availability Solutions
ScyllaDB Solutions by Industry
ScyllaDB Cloud Services
  1. Home
  2. > Blogs
  3. > TiDB
  4. > Sync-Diff-Inspector: Your Go-To Tool for Verifying Data Consistency Across TiDB and MySQL

Sync-Diff-Inspector: Your Go-To Tool for Verifying Data Consistency Across TiDB and MySQL

A powerful tool to compare, detect, and fix data inconsistencies across distributed databases—ensure accurate migrations and seamless replication with Sync-Diff-Inspector.

Abishek S May 05, 2025

Subscribe for email updates

Ensuring data consistency during database migration and replication is a critical challenge, especially in distributed environments. Whether migrating from MySQL to TiDB or verifying data integrity between two TiDB clusters, maintaining accuracy is essential to prevent data loss or corruption.

 

This is where Sync-Diff-Inspector comes in. It is a powerful tool that helps compare and validate data across databases, detecting inconsistencies and generating SQL fixes to ensure data remains accurate. 

 

In this guide, we’ll walk you through how to use Sync-Diff-Inspector for data validation, covering configuration details, real-world examples, and effective strategies to resolve inconsistencies.

 

Sync-diff-inspector

 

Sync-diff-inspector is a TiDB tool designed to compare and verify data consistency between two databases. It is particularly useful for ensuring data integrity after data migration processes, such as TiDB Data Migration (DM). The tool can identify the discrepancies between databases and generate SQL statements to repair the inconsistencies found.

 

Key features

  • Compare the table schema and data
  • Generate the SQL statements used to repair data if the data inconsistency exists
  • Support data check for tables with different schema or table names
  • Support data check in the sharding scenario
  • Support data check for TiDB upstream-downstream clusters
  • Support data check in the DM replication scenario

 

Use Cases of Sync-Diff-Inspector in TiDB-DM

  • Comparing data between MySQL and TiDB, or between two TiDB databases.
  • Checking data consistency in sharding scenarios, where data from multiple MySQL instances is replicated into TiDB.
  • Verifying data consistency in TiDB upstream-downstream clusters (TiCDC).

 

 

Database privileges for sync-diff-inspector

 

Upstream Database

 

 

Downstream Database

 

 

Data Validation using Sync-Diff-Inspector

 

Checking data counts in Source (MySQL) and Destination (TiDB)

 

MySQL

 

mysql> select count(*) from students;
+----------+
| count(*) |
+----------+
|        15|
+----------+
1 row in set (0.00 sec)

 

TiDB

 

mysql> select count(*) from test.students;
+----------+
| count(*) |
+----------+
|       14 |
+----------+
1 row in set (0.00 sec)

The missing row in TiDB may be due to replication lag, sharding inconsistencies, or migration failures.

 

Sync-Diff-Inspector Config File Example

 

# Diff Configuration.

######################### Global config #########################
# The number of goroutines created to check data.
check-thread-count = 4

# If enabled, SQL statements is exported to fix inconsistent tables.
export-fix-sql = true

# Only compares the data instead of the table structure.
check-data-only = false

# Only compares the table structure instead of the data.
check-struct-only = false

# If enabled, sync-diff-inspector skips checking tables that do not exist in the upstream or downstream.
skip-non-existing-table = true

######################### Datasource config #########################
[data-sources]
[data-sources.mysql1] # mysql1 is the only custom ID for the database instance.
  host = "127.0.0.1"
  port = 3306
  user = "root"
  password = "*****" 

[data-sources.tidb0]
  host = "127.0.0.1"
  port = 4000
  user = "root"
  password = “”

######################### task config #########################
# Configures the tables of the target database that need to be compared.
[task]

  output-dir = "/home/tidb/output"
  
  # The upstream database.
  source-instances = ["mysql1"]
  
  # The downstream database.
  target-instance = “tidb0”

  target-check-tables = ["test.students"]

 

Running the Validation 

 

./sync_diff_inspector --config sync_diff.toml
A total of 1 tables need to be compared

Comparing the table structure of ``test`.`students`` ... equivalent
Comparing the table data of ``test`.`students`` ... failure
_____________________________________________________________________________
Progress [============================================================>] 100% 0/0
The data of `test`.`students` is not equal


The rest of tables are all equal.


A total of 1 tables have been compared, 0 tables finished, 1 tables failed, 0 tables skipped.
The patch file has been generated in 
'/home/tidb/output/fix-on-tidb0/'
You can view the comparision details through ‘/home/tidb/output/sync_diff.log’

 

Analyzing the Comparison Results

 

After the check is finished, the sync-diff-inspector outputs a report file summary.txt located in output-dir = "/home/tidb/output".

 

Summary

Source Database

host = "127.0.0.1"
port = 3306
user = "root"


Target Databases

host = "127.0.0.1"
port = 4000
user = "root"


Comparison Result

The table structure and data in following tables are equivalent

The following tables contains inconsistent data

+-------------------+---------+--------------------+----------------+---------+-----------+
|       TABLE       | RESULT  | STRUCTURE EQUALITY | DATA DIFF ROWS | UPCOUNT | DOWNCOUNT |
+-------------------+---------+--------------------+----------------+---------+-----------+
| `test`.`students` | succeed | true               | +2/-1          |      15 |        14 |
+-------------------+---------+--------------------+----------------+---------+-----------+

Time Cost: 15.250426ms
Average Speed: 0.018823MB/s

 

Fixing Data Inconsistencies

 

If different rows exist during the data checking process, the SQL statements will be generated to fix them. The SQL file is located at ${output}/fix-on-${instance}, and ${instance} is the value of task.target-instance in the config.toml file.

 

-- table: test.students
-- range in sequence: Full
/*
  DIFF COLUMNS ╏     `NAME`      
╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╋╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍
  source data  ╏ 'Alice Smith'   
╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╋╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍
  target data  ╏ 'Alicee Smith'  
╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╋╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍
*/
REPLACE INTO `test`.`students`(`student_id`,`name`,`grade`) VALUES (101,'Alice Smith','A');
REPLACE INTO `test`.`students`(`student_id`,`name`,`grade`) VALUES (115,'Olivia Adams','A');

 

Best Practices for Using Sync-Diff-Inspector

 

Resource Management: Sync-Diff-Inspector consumes server resources while checking data. Avoid running it during peak business hours to prevent performance impact.

 

Collation Handling: When comparing MySQL and TiDB, ensure the collation settings are consistent, especially if primary or unique keys use VARCHAR. Mismatched collations can lead to incorrect validation results. Adjust collation settings in the configuration file as needed.

 

Data Chunking Accuracy: Sync-Diff-Inspector divides data into chunks based on TiDB statistics. Ensure accurate statistics by running ANALYZE TABLE {table_name} during low workload periods.

 

Table Mapping & Sharding: Pay close attention to table mapping rules. If a table in the source database has the same name as one in the target database, sharding may be applied by default. Properly configure schema-pattern and table-pattern to avoid unintended comparisons.

 

SQL Fix Verification: The generated SQL statements for data fixes serve as a reference. Always review and validate them before execution to prevent unintended modifications.

 

Restrictions

  • Online verification is not available for data migration between MySQL and TiDB. Ensure that no data is written to the upstream-downstream checklist and that data within a specified range remains unchanged. You can define this range using the range parameter.
  • In TiDB and MySQL, FLOAT, DOUBLE, and other floating-point types are handled differently. Checksums consider 6 and 15 significant digits for FLOAT and DOUBLE, respectively. To skip verifying these columns, set ignore-columns.
  • Tables without a primary key or unique index can be checked. However, if inconsistencies are found, the generated SQL statements may not accurately repair the data.

 

Conclusion

 

Sync-Diff-Inspector is your go-to tool for making sure data lines up perfectly across different databases, like MySQL and TiDB, or even between two TiDB setups. It spots any differences, checks if migrations went smoothly, and can even whip up SQL fixes, making data syncing rock solid for replication, migrations, and sharding.

 

To minimize risks, always review the generated SQL fixes before execution, monitor collation settings, and leverage TiDB statistics for improved accuracy. By integrating Sync-Diff-Inspector into your database management workflow, you can maintain data integrity and ensure smooth, reliable operations in your distributed database environment.

 

Author Bio

Abishek S

Abishek S is a MongoDB and TiDB Certified DBA at Mafiree with strong expertise in distributed databases, TiDB architecture, and cross-database consistency tools. He writes technical content focused on practical database solutions, data consistency verification, replication strategies, and performance optimization for modern data platforms. His work helps engineers and DBAs improve reliability and efficiency in real-world database operations.

Leave a Comment

Related Blogs

Manage Large Data Import in TiDB

Efficiently import massive datasets into TiDB clusters using TiDB Lightning for faster analytics and scalable performance.

  1271 views
Automate Expired Data Deletion in TiDB with TTL

Say goodbye to manual cleanup! Learn how TiDB’s TTL feature automates expired data deletion and keeps your database lean and efficient.

  1807 views
The Feature You’ve Been Looking For – Speed Up Your Queries with TiDB Cached Tables!

Boost database performance with TiDB cached tables—reduce latency and accelerate read-heavy queries.

  1523 views
Introducing Foreign Keys and more: Exploring New Features in TiDB v8.5.0

Explore the latest features in TiDB v8.5.0, including support for Foreign Keys, improved performance, and enhanced security for modern database management.

  1803 views
Optimizing Data Storage with TiDB Placement Rules

Leveraging TiDB’s Placement Rules for Optimal Performance

  1653 views

Subscribe for email updates

Get in touch with us

Highlights

More than 6000 Servers Monitored

Happy Clients

Certified DBAs

24 x 7 x 365 Support

PCI

Database Services

MySQL MongoDB PostgreSQL SQL Server Aerospike Clickhouse TiDB MariaDB Columnstore

Quick Links

Careers Blog Contact Privacy Policy Disclaimer Policy

Contacts

Linkedin Mafiree Facebook Mafiree Twitter Mafiree

Nagercoil Office

Miru IT Park, Vallankumaranvillai,

Nagercoil, Tamilnadu - 629 002.

Bangalore Office

Unit 303, Vanguard Rise,

5th Main, Konena Agrahara,

Old Airport Road, Bangalore - 560 017.

Call: +91 6383016411

Email: sales@mafiree.com


Copyright © - All Rights Reserved - Mafiree