0

我正在尝试比较来自两个独立数据库的两个 MySql 表,一个使用 MyIsam 引擎,另一个使用 InnoDb 引擎。

我需要能够快速确定表是否存储相同的值。我通过使用 MD5 哈希比较开始这个,但是失败了;我认为这是因为数据库引擎不同。

有人对我如何比较这两个表是否相等有任何建议吗?

注意

这是一个用 C#.NET 编写的应用程序,所以我更喜欢 C# 实现,而不是 MySql 引擎实现。通常,每个表总是有 210 列和 0 到 100 行之间的任意位置。

4

1 回答 1

1

当然,这不是大型表格的解决方案,并且自动增量不同。您可以通过某个特定事件的 cron 作业自动执行此操作,或者如果您说在某个表中插入一个 cron 作业看到、清除并开始它的值。

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"
于 2013-05-20T15:07:24.047 回答