mysql mysqldbcompare compares structural differences and data differences between two databases

Reference: https://www.wenjiangs.com/article/mysqldbcompare.html

  1. Install tool mysqldbcompare (version: 1.6.5): https://downloads.mysql.com/archives/utilities/
  2. download example

insert image description here
3. After installation, open the cmd command line to execute and check whether the installation is successful

mysqldbcompare

insert image description here
4. Executing instructions to compare database differences
Example 1 : The same server but different databases

mysqldbcompare --server1=root:root@localhost:3306 db_a:db_b --difftype=sql --run-all-tests

db_aModify the sum according to the actual situation db_b
--difftype=sql: print out the statement for repairing the difference, execute the statement to repair the difference between the databases
--run-all-tests: run a complete comparison, and do not stop when the first difference is encountered (if this is not configured, it will stop when the difference is encountered, resulting in The difference sql cannot be output, it is recommended to configure), note that the comparison of different tables will be skipped.

Example 2 : Different servers, different databases

$ mysqldbcompare --server1=root:root@localhost --server2=root:root@localhost db1:db2 --changes-for=server1 -a --difftype=sql --run-all-tests


# WARNING: Objects in server1.db1 but not in server1.db2:
# TABLE: table2
#
# WARNING: Objects in server1.db2 but not in server1.tb1:
# TABLE: table3
#
#                                                   Defn    Row     Data
# Type      Object Name                             Diff    Count   Check
#-------------------------------------------------------------------------
# TABLE     t1                                      pass    pass    -
#           - Compare table checksum                                FAIL
#           - Find row differences                                  FAIL
#
# Transformation for --changes-for=server1:
#

# Data differences found among rows:
UPDATE db1.t1 SET b = 'Test 123' WHERE a = '1';
UPDATE db1.t1 SET b = 'Test 789' WHERE a = '3';
DELETE FROM db1.t1 WHERE a = '4';
INSERT INTO db1.t1 (a, b) VALUES('5', 'New row - db2');

# Database consistency check failed.
#
# ...done
  1. More parameter descriptions:
  • --server1: MySQL server 1 configuration.
  • --server2: MySQL server 2 configuration. If it is the same server, –server2 can be omitted.
  • db1:db2: The two databases to compare. If comparing databases with the same name on different servers, :db2 can be omitted.
  • --all: Compare all databases with the same name on all two servers. --exclude excludes databases that do not need to be compared.
  • --run-all-tests: Run a full compare, without stopping when the first difference is encountered.
  • --changes-for=: Modify the object. For example –changes-for=server2, then the comparison is based on server1, and the modification of the generated difference is also the modification of the object of server2.
  • -d DIFFTYPE,--difftype=DIFFTYPE: The way to display the difference information, there are [unified|context|differ|sql], the default is unified. If you use sql, then directly generate the difference SQL, which is very convenient.
  • --show-reverse: In the generated differential modification, the modification of server2 and server1 will be included at the same time.
  • --skip-table-options: Keep the options of the table unchanged, that is, the differences in the comparison do not include differences such as table names, AUTO_INCREMENT, ENGINE, and CHARSET.
  • --skip-diff: Skip object definition comparison check. The so-called object definition is the part inside the CREATE statement (), and --skip-table-options is the part outside ().
  • --skip-object-compare: By default, objects that are missing from each other in both databases are checked first, and then differences between objects that exist in both are checked. The function of this parameter is to skip the first step and not to check for mutually missing objects.
  • --skip-checksum-table: Skip CHECKSUM TABLE during data consistency verification.
  • --skip-data-check: Skip data consistency verification.
  • --skip-row-count: Skip field count check.
  1. question
  • ERROR: The list of objects differs among database db_a and db_b.
    Indicates that the names of tables in the two databases are different

Guess you like

Origin blog.csdn.net/u014438244/article/details/127575442