我曾经使用Adam Spiers' mysqldiff工具,但它已经很多年没有维护了,所以在新的服务器上我尝试使用包含类似工具的mysql-utilities软件包。但即使我比较具有完全相同模式的两个数据库,它们的名称不同(duh!)的事实足以让工具说比较失败(这似乎是找到差异的强有力的词,但我猜这& #39;它是如何工作的)。这是输出:
[root](22:05:48)[~]$ mysqldiff --server1=root:mypassword@localhost kizuna_master:kizuna_misa
# server1 on localhost: ... connected.
# Comparing `kizuna_master` to `kizuna_misa` [FAIL]
# Object definitions differ. (--changes-for=server1)
#
--- `kizuna_master`
+++ `kizuna_misa`
@@ -1 +1 @@
-CREATE DATABASE `kizuna_master` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci */
+CREATE DATABASE `kizuna_misa` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci */
Compare failed. One or more differences found.
在这种情况下,如果比较同一台服务器上的两个数据库,它总是会失败 - 这是没有意义的。我做错了吗?
编辑:根据Solarflare的建议,我也试过了mysqldbcompare:
mysqldbcompare --skip-row-count --skip-data-check --run-all-tests --server1=root:mypassword@localhost kizuna_master:kizuna_dev
但它的结果与mysqldiff相同,但更有讽刺意味。使用这两个命令,它不仅在CREATE DATABASE
定义上失败,而且在具有自动递增键字段的所有表上也失败!好悲伤 - 如果我说我不想比较数据( - skip-data-check),为什么我认为我希望它因AUTO_INCREMENT
而失败?以下是上述mysqldbcompare
调用的输出的第一部分:
# server1 on localhost: ... connected.
# Checking databases kizuna_master and kizuna_dev on server1
#
# Object definitions differ. (--changes-for=server1)
#
--- `kizuna_master`
+++ `kizuna_dev`
@@ -1 +1 @@
-CREATE DATABASE `kizuna_master` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci */
+CREATE DATABASE `kizuna_dev` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci */
# Defn Row Data
# Type Object Name Diff Count Check
# -------------------------------------------------------------------------
# TABLE action FAIL SKIP SKIP
#
# Object definitions differ. (--changes-for=server1)
#
--- `kizuna_master`.`action`
+++ `kizuna_dev`.`action`
@@ -9,4 +9,4 @@
KEY `PersonID` (`PersonID`),
KEY `ContactTypeID` (`ActionTypeID`),
CONSTRAINT `action_ibfk_1` FOREIGN KEY (`ActionTypeID`) REFERENCES `actiontype` (`ActionTypeID`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
+) ENGINE=InnoDB AUTO_INCREMENT=1953 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
# TABLE actiontype FAIL SKIP SKIP
#
# Object definitions differ. (--changes-for=server1)
#
--- `kizuna_master`.`actiontype`
+++ `kizuna_dev`.`actiontype`
@@ -4,4 +4,4 @@
`BGColor` char(6) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'FFFFFF',
`Template` text COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
PRIMARY KEY (`ActionTypeID`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
+) ENGINE=InnoDB AUTO_INCREMENT=22 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
# TABLE addrprint pass SKIP SKIP
# TABLE attendance pass SKIP SKIP
# TABLE category FAIL SKIP SKIP
#
# Object definitions differ. (--changes-for=server1)
#
--- `kizuna_master`.`category`
+++ `kizuna_dev`.`category`
@@ -4,4 +4,4 @@
`UseFor` enum('OP','P','O') CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'OP' COMMENT 'Whether the category can be used for people, orgs,
or both',
PRIMARY KEY (`CategoryID`),
KEY `Category` (`Category`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
+) ENGINE=InnoDB AUTO_INCREMENT=101 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
等...整个事情就是这样。
编辑#2:添加--skip-table-options
让它对自动增量保持沉默,虽然我不知道该选项会忽略的其他差异以及我是否关心。但是,虽然它仍然报告了数据库名称的差异,但它并没有使用“#34; fail"不再,所以我想这是一个改进。以下是mysqldbcompare --skip-row-count --skip-data-check --run-all-tests --skip-table-options --difftype=differ --server1=root:mypassword@localhost kizuna_master:kizuna_dev
的输出:
# server1 on localhost: ... connected.
# Checking databases kizuna_master and kizuna_dev on server1
#
# Object definitions differ. (--changes-for=server1)
#
- CREATE DATABASE `kizuna_master` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci */
? ^^^^ ^
+ CREATE DATABASE `kizuna_dev` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci */
? ^ ^
# Defn Row Data
# Type Object Name Diff Count Check
# -------------------------------------------------------------------------
# TABLE action pass SKIP SKIP
# TABLE actiontype pass SKIP SKIP
# TABLE addrprint pass SKIP SKIP
# TABLE attendance pass SKIP SKIP
# TABLE category pass SKIP SKIP
# TABLE config pass SKIP SKIP
# TABLE custom pass SKIP SKIP
# TABLE donation pass SKIP SKIP
# TABLE donationtype pass SKIP SKIP
# TABLE event pass SKIP SKIP
# TABLE household pass SKIP SKIP
# TABLE labelprint pass SKIP SKIP
# TABLE loginlog pass SKIP SKIP
# TABLE output pass SKIP SKIP
# TABLE outputset pass SKIP SKIP
# TABLE percat pass SKIP SKIP
# TABLE perorg pass SKIP SKIP
# TABLE person pass SKIP SKIP
# TABLE photoprint pass SKIP SKIP
# TABLE pledge pass SKIP SKIP
# TABLE postalcode pass SKIP SKIP
# TABLE preselect pass SKIP SKIP
# TABLE upload pass SKIP SKIP
# TABLE uploadtype pass SKIP SKIP
# TABLE user pass SKIP SKIP
# Databases are consistent given skip options specified.
#
# ...done
所以我想在我的bash脚本中我可以将其输入grep并检查单词" fail"。但真是一团糟 - 旧mysqldiff
工具如此简单明了。
另一个问题是关于工具版本。 mysqldiff --help
说:" MySQL Utilities mysqldiff版本1.3.6(MySQL Workbench Distribution 5.2.47的一部分)"。我最初直接下载了最新的,但它不会安装 - 这就是yum可以在CentOS7上给我的东西。我的数据库是MariaDB 10.2.8,如果这很重要的话。 (当我开始讨论时,它是10.2.4,但从那时起我就更新了。)
答案 0 :(得分:0)
我遇到了同样的问题,但找到了解决方案。 mysqldiff和mysqldbcompare都来自mysql-utilities,所以共享相同的代码库。
在我的情况下,我需要对应该具有相同结构但不具有相同名称的数据库运行laravel迁移。当我运行mysqldbcompare --version
时,它会显示
MySQL Utilities mysqldbcompare版本1.6.1
许可证类型:GPLv2
现在,就像你一样,我试着检查数据库结构
mysqldbcompare --server1={server1} --server2={server1} --difftype=sql --skip-row-count --skip-data-check --run-all-tests --skip-table-options --changes-for=server2 {db1}:{db2}
在股票ubuntu 16.04上,mysqldbcompare引发了同样的错误,抱怨不同的数据库名称:
# WARNING: Using a password on the command line interface can be insecure.
# server1 on localhost: ... connected.
# server2 on localhost: ... connected.
# Checking databases backend_21 on server1 and backend_1 on server2
#
# WARNING: Cannot generate SQL statements for these objects.
# Check the difference output for other discrepencies.
--- `backend_21`
+++ `backend_1`
@@ -1 +1 @@
-CREATE DATABASE `backend_21` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci */
+CREATE DATABASE `backend_1` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci */
# WARNING: Could not generate SQL statements for differences between `backend_21` and `backend_1`. No changes required or not supported difference.
# WARNING: Cannot generate SQL statements for these objects.
# Check the difference output for other discrepencies.
--- `backend_21`
+++ `backend_1`
@@ -1 +1 @@
-CREATE DATABASE `backend_21` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci */
+CREATE DATABASE `backend_1` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci */
# Defn Row Data
# Type Object Name Diff Count Check
# -------------------------------------------------------------------------
# TABLE bot_bus_connections pass SKIP SKIP
...
# TABLE user_settings pass SKIP SKIP
# Databases are consistent given skip options specified.
#
# ...done
经过一些调查后,我发现此行为已经报告错误,并且在1.6.4版中修复了:https://bugs.mysql.com/bug.php?id=77058。
因此,在手动升级这些python文件之后,我现在使用
运行mysqldbcompare --version
MySQL Utilities mysqldbcompare版本1.6.4
许可证类型:GPLv2
结果如预期:
# WARNING: Using a password on the command line interface can be insecure.
# server1 on localhost: ... connected.
# server2 on localhost: ... connected.
# Checking databases backend_21 on server1 and backend_1 on server2
#
# Defn Row Data
# Type Object Name Diff Count Check
# -------------------------------------------------------------------------
# TABLE bot_bus_connections pass SKIP SKIP
...
# TABLE user_settings pass SKIP SKIP
# Databases are consistent given skip options specified.
#
# ...done
然而,还有一件令人烦恼的事情是忽略CREATE TABLE
陈述。所以,如果database1(我的模板数据库)中有新表,它只会抛出一个警告:
# WARNING: Objects in server1.backend_1 but not in server1.backend_2:
# TABLE: statistic_chats
# TABLE: localizations
# TABLE: statistic_customers
自2015年以来也有报道,但到目前为止还没有对mysql的反应。我有点肮脏的解决方案
CREATE TABLE
语句,因此表格存在且希望有所帮助。
干杯