mysql / mysql-utilities

MySQL Utilities is a set of easy-to-use scripts intended to make working with MySQL servers easier.
GNU General Public License v2.0
267 stars 161 forks source link

Mysqldiff error: when the associated query primary key index is established on multiple columns, the diff result is wrong #53

Open lizhiyou88 opened 2 years ago

lizhiyou88 commented 2 years ago

table structure in server1: CREATE TABLE t1 ( a int NOT NULL, b char(10) NOT NULL, c varchar(100) DEFAULT '', PRIMARY KEY (a,b), KEY idx_a_b (a,b) )

table structure in server2: CREATE TABLE t1 ( a int(11) NOT NULL AUTO_INCREMENT, b char(10) DEFAULT NULL COMMENT '保证金', c varchar(100) NOT NULL DEFAULT '', d datetime DEFAULT NULL, e datetime DEFAULT NULL, PRIMARY KEY (a), KEY idx_b_c (b,c) )

--changes-for=server1 result : ALTER TABLE test.t1 DROP PRIMARY KEY, DROP PRIMARY KEY, DROP INDEX idx_a_b, ADD PRIMARY KEY(a), ADD INDEX idx_b_c (b,c), CHANGE COLUMN a a int(11) NOT NULL AUTO_INCREMENT, ADD COLUMN e datetime NULL, ADD COLUMN d datetime NULL AFTER c, CHANGE COLUMN c c varchar(100) NOT NULL DEFAULT '', CHANGE COLUMN b b char(10) NULL COMMENT '保证金', AUTO_INCREMENT=3, COLLATE=utf8_general_ci;

If it is a federated primary key, "drop primary key" will generate multiple primary keys

image