github上的MySQL数据库结构同步工具,真的很好用,还能自动生成升级脚本。如果能生成数据库差异报告就更好了,这样可以先评估变更的影响。
源代码网址:https://github.com/mmatuson/SchemaObject
运行结果:
python3 sync_mysql_schema.py mysql://xxx:xxxxx@localhost:3306/test1 mysql://xxx:xxxxx@localhost:3306/test2
=== start compare mysql db schema ===
** sync mysql schema from database `localhost-test1` to database `localhost-test2`, current step is sync database options **
** sync mysql schema from database `localhost-test1` to database `localhost-test2`, current step is sync tables, create table **
** sync mysql schema from database `localhost-test1` to database `localhost-test2`, current step is sync tables, drop table **
** sync mysql schema from database `localhost-test1` to database `localhost-test2`, current step is sync cloumns, index, foreignkey, table options **
ALTER TABLE `t1` DROP COLUMN `addr`, MODIFY COLUMN `id` int(10) NULL FIRST, MODIFY COLUMN `name` varchar(100) NULL AFTER `id`;
=== end compare mysql db schema ===
exec sync ddl sql on target db? [Y/N]n
=== thank you for use, Bye! ===