Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support sync DDL from Oracle to MySQL #811

Closed
sjjian opened this issue Nov 24, 2021 · 1 comment
Closed

support sync DDL from Oracle to MySQL #811

sjjian opened this issue Nov 24, 2021 · 1 comment
Assignees
Labels

Comments

@sjjian
Copy link
Member

sjjian commented Nov 24, 2021

方案(实现)

  • MySQL - MySQL DDL的同步为,源端将binglog中获取的DDL SQL传输到 目标端,目标端直接执行DDL.
  • Oracle - MySQL 同步过程与MySQL-MySQL使用了相同的中间态结构传输. 考虑将Oracle获取的DDL 转为MySQL格式的DDL.
  1. dtle借助工具logminer , 从oracle 获取DDL SQL.
  2. 使用三方库OracleParse库解析oracle的DDL,解析出Oracle的语法结构
  3. 根据解析出来的 SQL 类型和字段类型(类型转换) 通过字符匹配拼接方式构造为MySQL格式的DDL同步到目标端
  4. 目标端执行同步过来的SQL

DDL 支持度

SQL类型 Option Oracle SQL 转化后MySQL SQL 语法支持 不支持字段类型
CREATE TABLE 不带约束 CREATE TABLE test."persons"("first_name" VARCHAR(15) NOT NULL,last_name VARCHAR2(45) NOT NULL); CREATE TABLE TEST.persons (first_name VARCHAR(15),LAST_NAME VARCHAR(45)) 支持
CREATE TABLE 带约束 暂未支持
ALTER TABLE AddColumnClase ALTER TABLE test."persons" ADD alter_name1 VARCHAR2 ( 30 )) ADD ( alter_name2 VARCHAR2 ( 30 )); ALTER TABLE TEST.persons ADD COLUMN(ALTER_NAME1 VARCHAR(30)),ADD COLUMN(ALTER_NAME2 VARCHAR(30)) 支持
ALTER TABLE ModifyColumnClause ALTER TABLE test."persons" MODIFY ( alter_new_name1 CHAR ( 13 )) MODIFY ( alter_name2 VARCHAR ( 66 )) ALTER TABLE TEST.persons MODIFY COLUMN(ALTER_NEW_NAME1 CHAR(13)),MODIFY COLUMN(ALTER_NAME2 VARCHAR(66)) 支持
ALTER TABLE DropColumnClause ALTER TABLE "TEST"."persons" DROP ("DROP_NAME1",drop_name2) ALTER TABLE TEST.persons DROP COLUMN(DROP_NAME1,DROP_NAME2) 支持
ALTER TABLE RenameColumnClase ALTER TABLE "TEST"."persons" RENAME COLUMN "RE_NAME" TO "RE_NAME_NEW ALTER TABLE TEST.persons CHANGE COLUMN RE_NAME RE_NAME_NEW 当前仅支持8.0语法
DROP TABLE DROP TABLE test."persons DROP TABLE TEST.persons

类型转换

  • 类型转换参考链接
  • 文档变更点
    1.NClob 变更为text
    2.timestamp 在MySQL 最大长度为6
    3.MySQL中number字段最大scale为30
    4.INTEGET和INT应该对应MySQL中的decimal(38)或者INT都会出现长度不足的问题(40个9为可存储的最大值)
    5.ROW ID 字段对应长度10导致写入失败,修改为100

oracle number 类型 scale 小于0不支持

参考文档

@asiroliu
Copy link
Collaborator

version:

9.9.9.9-oracle_demo-1ffa8bf

oracle sql

-- create table
-- CREATE TABLE TEST.BFILE_COLUMNS(col1 INT, col2 BFILE);
CREATE TABLE TEST.BINARY_FLOAT_COLUMNS(col1 INT, col2 BINARY_FLOAT);
CREATE TABLE TEST.BINARY_DOUBLE_COLUMNS(col1 INT, col2 BINARY_DOUBLE);
CREATE TABLE TEST.BLOB_COLUMNS(col1 INT, col2 BLOB);
CREATE TABLE TEST.CLOB_COLUMNS(col1 INT, col2 CLOB);
CREATE TABLE TEST.CHAR_255_COLUMNS(col1 INT, col2 CHAR(255));
CREATE TABLE TEST.CHAR_2000_COLUMNS(col1 INT, col2 CHAR(2000));
CREATE TABLE TEST.CHARACTER_255_COLUMNS(col1 INT, col2 CHARACTER(255));
CREATE TABLE TEST.CHARACTER_2000_COLUMNS(col1 INT, col2 CHARACTER(2000));
CREATE TABLE TEST.DATE_COLUMNS(col1 INT, col2 DATE);
CREATE TABLE TEST.DECIMAL_COLUMNS(col1 INT, col2 DECIMAL(38, 10));
CREATE TABLE TEST.DEC_COLUMNS(col1 INT, col2 DEC(38, 10));
-- CREATE TABLE TEST.DOUBLE_PRECISION_COLUMNS(col1 INT, col2 DOUBLE PRECISION);
CREATE TABLE TEST.FLOAT_COLUMNS(col1 INT, col2 FLOAT(126));
CREATE TABLE TEST.INTEGER_COLUMNS(col1 INT, col2 INTEGER);
CREATE TABLE TEST.INT_COLUMNS(col1 INT, col2 INT);
CREATE TABLE TEST.INTERVAL_YEAR_COLUMNS(col1 INT, col2 INTERVAL YEAR(9) TO MONTH);
CREATE TABLE TEST.INTERVAL_DAY_COLUMNS(col1 INT, col2 INTERVAL DAY(9) TO SECOND(9));
CREATE TABLE TEST.LONG_COLUMNS(col1 INT, col2 LONG);
-- CREATE TABLE TEST.LONG_RAW_COLUMNS(col1 INT, col2 LONG RAW);
CREATE TABLE TEST.NCHAR_255_COLUMNS(col1 INT, col2 NCHAR(255));
CREATE TABLE TEST.NCHAR_1000_COLUMNS(col1 INT, col2 NCHAR(1000));
CREATE TABLE TEST.NCHAR_VARYING_COLUMNS(col1 INT, col2 NCHAR VARYING(2000));
-- CREATE TABLE TEST.NCLOB_COLUMNS(col1 INT, col2 NCLOB);
CREATE TABLE TEST.NUMBER_2_COLUMNS(col1 INT, col2 NUMBER(2));
CREATE TABLE TEST.NUMBER_4_COLUMNS(col1 INT, col2 NUMBER(4, 0));
CREATE TABLE TEST.NUMBER_8_COLUMNS(col1 INT, col2 NUMBER(8));
CREATE TABLE TEST.NUMBER_18_COLUMNS(col1 INT, col2 NUMBER(18, 0));
CREATE TABLE TEST.NUMBER_38_COLUMNS(col1 INT, col2 NUMBER(38));
CREATE TABLE TEST.NUMBER_38_30_COLUMNS(col1 INT, col2 NUMBER(38, 30));
CREATE TABLE TEST.NUMBER_COLUMNS(col1 INT, col2 NUMBER);
CREATE TABLE TEST.NUMBER_WILDCARD_COLUMNS(col1 INT, col2 NUMBER(*));
CREATE TABLE TEST.NUMERIC_COLUMNS(col1 INT, col2 NUMERIC(38, 30));
CREATE TABLE TEST.NVARCHAR2_COLUMNS(col1 INT, col2 NVARCHAR2(2000));
CREATE TABLE TEST.RAW_COLUMNS(col1 INT, col2 RAW(2000));
CREATE TABLE TEST.REAL_COLUMNS(col1 INT, col2 REAL);
CREATE TABLE TEST.ROWID_COLUMNS(col1 INT, col2 ROWID);
-- CREATE TABLE TEST.UROWID_COLUMNS(col1 INT, col2 UROWID(4000));
CREATE TABLE TEST.SMALLINT_COLUMNS(col1 INT, col2 SMALLINT);
CREATE TABLE TEST.TIMESTAMP_COLUMNS(col1 INT, col2 TIMESTAMP(9));
-- CREATE TABLE TEST.TIMESTAMP_ZONE_COLUMNS(col1 INT, col2 TIMESTAMP(9) WITH TIME ZONE);
CREATE TABLE TEST.VARCHAR_COLUMNS(col1 INT, col2 VARCHAR(4000));
CREATE TABLE TEST.VARCHAR2_COLUMNS(col1 INT, col2 VARCHAR2(4000));
-- CREATE TABLE TEST.XMLTYPE_COLUMNS(col1 INT, col2 XMLTYPE);

-- add col
CREATE TABLE TEST.T1(col1 VARCHAR(20));
ALTER TABLE TEST.T1 ADD ("a_col1" VARCHAR2 (20)) ADD (a_col2 NUMBER);

-- modify col
CREATE TABLE TEST.T2(col1 VARCHAR(20), col2 NUMBER);
ALTER TABLE TEST.T2 MODIFY ("COL1" NUMBER) MODIFY (col2 VARCHAR(20));

-- drop col
CREATE TABLE TEST.T3(col1 VARCHAR(20), col2 NUMBER, col3 INT);
ALTER TABLE TEST.T3 DROP ("COL1", col2);

-- drop table
CREATE TABLE TEST.T4(col1 VARCHAR(20), col2 NUMBER);
DROP TABLE TEST.T4;

@asiroliu asiroliu added the VERIFIED verified issue label Dec 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants