GithubHelp home page GithubHelp logo

hidu / mysql-schema-sync Goto Github PK

View Code? Open in Web Editor NEW
736.0 47.0 268.0 210 KB

mysql表结构自动同步工具(目前只支持字段、索引的同步,分区等高级功能暂不支持)

License: MIT License

Shell 0.60% Go 99.40%
mysql

mysql-schema-sync's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mysql-schema-sync's Issues

能不能讲下原理

我是java开发,不会go,想用这个工具,但是想知道下原理,一般是通过binlog同步的,不过这个工具是通过查询还是什么方式 不清楚

如何能不删除目的数据库中多出来的表

如何能不删除目的数据库中多出来的表
比如:目的DB 比 源DB 多出来一个表t1
在执行:mysql-schema-sync -conf mydb_conf.json 2>/dev/null >db_alter.sql
文件 db_alter.sql 中会有一个 drop table t1 的语句
咱们项目的 readme 中提到 “默认情况不会对多出的表、字段、索引、外键删除”
但还是会执行 drop 操作,这里是不是存在BUG ?

无法通过go install 安装

因为我的网络原因 无法通过go install 进行安装
我是否能将master.zip 下载下来进行编译呢?

db_index parse failed,unsupported,line:

2019/12/30 schemaSync.go:270: Index : 73 Table : sheet_histories
2019/12/30 db.go:86: [SQL] [source] show create table sheet_histories []
2019/12/30 db.go:86: [SQL] [dest] show create table sheet_histories []
2019/12/30 index.go:113: db_index parse failed,unsupported,line: ) ENGINE=InnoDB AUTO_INCREMENT=7814 DEFAULT CHARSET=utf8

what does this mean

某张表没有索引,报错了

image

show create table xx_activeuser_usage

CREATE TABLE xx_activeuser_usage (
account_id varchar(36) NOT NULL,
host_id varchar(36) NOT NULL,
start_date date NOT NULL,
PRIMARY KEY (account_id,start_date,host_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
/*!50100 PARTITION BY RANGE (TO_DAYS (start_date))
(PARTITION p201510 VALUES LESS THAN (736268) ENGINE = InnoDB,
PARTITION p201511 VALUES LESS THAN (736298) ENGINE = InnoDB,
PARTITION p201512 VALUES LESS THAN (736329) ENGINE = InnoDB,
PARTITION p201601 VALUES LESS THAN (736360) ENGINE = InnoDB,
PARTITION p201602 VALUES LESS THAN (736389) ENGINE = InnoDB,
PARTITION p201603 VALUES LESS THAN (736420) ENGINE = InnoDB,
PARTITION p201604 VALUES LESS THAN (736450) ENGINE = InnoDB,
PARTITION p201605 VALUES LESS THAN (736481) ENGINE = InnoDB,
PARTITION p201606 VALUES LESS THAN (736511) ENGINE = InnoDB,
PARTITION p201812 VALUES LESS THAN (737425) ENGINE = InnoDB) */

表同步有问题,

2020/07/21 db.go:71: Error 1146: Table 'clj.test1' doesn't exist
2020/07/21 index.go:113: db_index parse failed,unsupported,line: ) ENGINE=InnoDB DEFAULT CHARSET=utf8
test1 表没有索引

支持SSH隧道

数据库在防火墙后面,需要通过SSH隧道进行连接,希望能添加此功能

同步数据问题

该方案是只支持将数据结构从一个库同步到另一个库,还是同样也支持同一个库里主表和分表的结构同步

阿里云两个RDS实例同步没有信息

两个阿里云RDS同步,生成sql脚本,里面没有任何信息。去掉 2>/dev/null 看到查询都是空。
在同一个实例里两个库同步是正常的。

不能用,skip

2019/06/13 db.go:85: [SQL] [source] show table status []
2019/06/13 schemaSync.go:265: source db table total: 1
2019/06/13 schemaSync.go:270: Index : 0 Table : test
2019/06/13 schemaSync.go:277: Table: test skip
2019/06/13 schemaSync.go:303: trace changedTables: map[]
2019/06/13 schemaSync.go:352: execute_all_sql_done,success_total: 0 failed_total: 0
2019/06/13 statics.go:137: no table change,skip send mail

{
"source":"root:root@(192.168.1.189:3306)/test",
"dest":"root:root@(192.168.1.189:3306)/test2",
"tables":[],
"email":{
"send_mail":true,
"smtp_host":"",
"from":"
",
"password":"",
"to":"
"
}
}

问题

是否考虑出Windows版本

同步bug

source ---> dest
从邮件来看:
1.source有表,dest没有
2.after没了,alter after也没有
触发的操作:drop table table_name

然后在同步一 遍

CheckMatchIgnoreTables Bug?

func (cfg *Config) CheckMatchIgnoreTables(name string) bool {
	if len(cfg.TablesIGNORE) == 0 {
		return true  // ****should return false**** 
	}
	for _, tableName := range cfg.TablesIGNORE {
		if simpleMatch(tableName, name, "CheckMatchTables") {
			return true
		}
	}
	return false
}

当有表分区时无法同步

CREATE TABLE `tab_test` (
  `test_id` bigint(20) unsigned NOT NULL COMMENT 'id',
  `test_str` varchar(128) DEFAULT NULL,
  `test_time` int(11) unsigned NOT NULL COMMENT '时间戳',
 KEY `test_id` (`test_id`) USING BTREE,
 KEY `login_time` (`test_time`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='test'
/*!50100 PARTITION BY HASH (test_id)
PARTITIONS 10 */;

index.go:111: db_index parse failed,unsupport,line: ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='test'

对比结果不成功

root@ZabbixServer:~/downloads/go/src/github.com/hidu/mysql-schema-sync# ./mysql-schema-sync -conf config.json -sync
2019/05/29 db.go:85: [SQL] [source] show table status []
2019/05/29 schemaSync.go:265: source db table total: 85
2019/05/29 schemaSync.go:270: Index : 0 Table : ti_account
2019/05/29 schemaSync.go:277: Table: ti_account skip
2019/05/29 schemaSync.go:270: Index : 1 Table : ti_account_activity_collect
2019/05/29 schemaSync.go:277: Table: ti_account_activity_collect skip
2019/05/29 schemaSync.go:270: Index : 2 Table : ti_account_attention_act
2019/05/29 schemaSync.go:277: Table: ti_account_attention_act skip
2019/05/29 schemaSync.go:270: Index : 3 Table : ti_account_auth
2019/05/29 schemaSync.go:277: Table: ti_account_auth skip
2019/05/29 schemaSync.go:270: Index : 4 Table : ti_account_auth_backup
2019/05/29 schemaSync.go:277: Table: ti_account_auth_backup skip
2019/05/29 schemaSync.go:270: Index : 5 Table : ti_account_blacklist
2019/05/29 schemaSync.go:277: Table: ti_account_blacklist skip
2019/05/29 schemaSync.go:270: Index : 6 Table : ti_account_cover
2019/05/29 schemaSync.go:277: Table: ti_account_cover skip
2019/05/29 schemaSync.go:270: Index : 7 Table : ti_account_cover_edit_verify
2019/05/29 schemaSync.go:277: Table: ti_account_cover_edit_verify skip
2019/05/29 schemaSync.go:270: Index : 8 Table : ti_account_destroy
2019/05/29 schemaSync.go:277: Table: ti_account_destroy skip
2019/05/29 schemaSync.go:270: Index : 9 Table : ti_account_edit_record
2019/05/29 schemaSync.go:277: Table: ti_account_edit_record skip
2019/05/29 schemaSync.go:270: Index : 10 Table : ti_account_edit_verify
2019/05/29 schemaSync.go:277: Table: ti_account_edit_verify skip
2019/05/29 schemaSync.go:270: Index : 11 Table : ti_account_intent
2019/05/29 schemaSync.go:277: Table: ti_account_intent skip
2019/05/29 schemaSync.go:270: Index : 12 Table : ti_account_invite
2019/05/29 schemaSync.go:277: Table: ti_account_invite skip
2019/05/29 schemaSync.go:270: Index : 13 Table : ti_account_last_edit_log
2019/05/29 schemaSync.go:277: Table: ti_account_last_edit_log skip

表同步出现错误,想问一下最低支持的mysql版本

EXEC_SQL_FAIELD Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ';
ALTER TABLE n_system_apply
ADD CONSTRAINT FK_10egw3bdhwrghm091ueehk8te FOR' at line 3
c9ebe276095a131821bdb5c44a534ec9

Couldn't send email and got errors

after I ran the script,I got the message below:
email.go:76: send mail failed,err: x509: certificate is valid for *.263.net, 263.net, not smtp.xxxx.com
what's wrong with it?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.