简体   繁体   中英

Comparing InnoDb and MyIsam MySql Tables for Equality

I am trying to compare two MySql tables from two separate databases, one uses a MyIsam engine and the other uses an InnoDb engine.

I need to be able to quickly determine whether the tables store identical values or not. I started this by using an MD5 hash comparison but that failed; I think its because the db engines are different.

Does anyone have any advice as to how I could compare the two tables for equality?

NOTE :

This is an application that is being written in C#.NET, so I would prefer a C# implementation, not a MySql engine implementation. In general, there are always 210 columns and anywhere between 0 and 100 rows per table.

not a solution for huge tables of course, and auto increments that are different. you could automate this with a cron job with a certain occurrence or if you say plop a value in a certain table that the cron job sees, clears, and begins it.

CREATE TABLE charlie1
(   billybob INT NOT NULL,
    birthdate DATETIME NOT NULL,
    funny_num FLOAT NOT NULL
)ENGINE=INNODB;

INSERT INTO charlie1 (billybob,birthdate,funny_num) VALUES (1,'2006-01-02',28832.123);
INSERT INTO charlie1 (billybob,birthdate,funny_num) VALUES (2,'2004-09-02',18832.888);
INSERT INTO charlie1 (billybob,birthdate,funny_num) VALUES (3,'2006-07-03',28332.123);
INSERT INTO charlie1 (billybob,birthdate,funny_num) VALUES (4,'2006-01-02',28852.777);


SELECT billybob,birthdate,funny_num
FROM charlie1
ORDER BY billybob
INTO OUTFILE '/tmp/charlie1.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'

CREATE TABLE charlie2
(   billybob INT NOT NULL,
    birthdate DATETIME NOT NULL,
    funny_num FLOAT NOT NULL
)ENGINE=MYISAM;

INSERT INTO charlie2 (billybob,birthdate,funny_num) VALUES (1,'2006-01-02',28832.123);
INSERT INTO charlie2 (billybob,birthdate,funny_num) VALUES (2,'2004-09-02',18832.888);
INSERT INTO charlie2 (billybob,birthdate,funny_num) VALUES (3,'2006-07-03',28332.123);
INSERT INTO charlie2 (billybob,birthdate,funny_num) VALUES (4,'2006-01-02',28852.777);


SELECT billybob,birthdate,funny_num
FROM charlie2
ORDER BY billybob
INTO OUTFILE '/tmp/charlie2.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'

i changed data in the file to show diff picks it up:

root@hp:/tmp# diff /tmp/charlie1.csv /tmp/charlie2.csv
2c2
< "2","2004-09-02 00:00:00","18832.9"
---
> "2","2004-09-02 00:00:00","18832.8"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM