- 简介
- 环境依赖
- 快速上手
- 配置文件
- 命令介绍
- mtk
- init-project
- config
- license
- mig
- show
- sync
- sync-schema
- sync-sequence
- sync-object-type
- sync-domain
- sync-wrapper
- sync-server
- sync-user-mapping
- sync-queue
- sync-table
- sync-nickname
- sync-rule
- sync-table-data
- sync-table-data-estimate
- sync-index
- sync-constraint
- sync-db-link
- sync-view
- sync-mview
- sync-function
- sync-procedure
- sync-package
- sync-trigger
- sync-synonym
- sync-table-data-com
- sync-alter-sequence
- sync-coll-statistics
- check-table-data
- gen
- gen completion
- encrypt
- convert-plsql
- report
- self
- mvd
- usql
- 图形化
- 常见问题
- Release
使用MTK迁移MySQL到openGauss/MogDB
支持版本
- 5.5
- 5.6
- 5.7
- 8.0
注意事项
空字符串和NULL值问题
- openGauss A模式下和MySQL不一样,需要处理数据 当列的属性为
NOT NULL
时转为" "
,允许为NULL时转为NULL - openGauss PG模式下和MySQL一样, NULL !=
''
无需处理 - openGauss B模式下和MySQL一样, NULL !=
''
无需处理
数据库兼容类型。取值范围: A、B、C、PG。分别表示兼容Oracle、MySQL、Teradata和PostgreSQL。但是C目前已经放弃支持。因此常用的取值是A、B、PG。
说明:
- A兼容性下,数据库将空字符串作为NULL处理,数据类型DATE会被替换为TIMESTAMP(0) WITHOUT TIME ZONE。
- 将字符串转换成整数类型时,如果输入不合法,B兼容性会将输入转换为0,而其它兼 容性则会报错。
- PG兼容性下,CHAR和VARCHAR以字符为计数单位,其它兼容性以字节为计数单位。例如,对于UTF-8字符集,CHAR(3)在PG兼容性下能存放3个中文字符,而在其它兼容性下只能存放1个中文字符。
COLLATE/Charset
MySQL 的 COLLATE 分为以下级别
- 实例级别
- 数据库级别
- 表级别
- 列级别
- 连接级别
MogDB 的 COLLATE 在 B 模式 dolphin 下为以下级别
- 实例级别
- 数据库级别
- Schema
- 表级别
- 列级别
不支持同一个数据库/表下存在多个字符集场景,迁移到MogDB只能为一个字符集, 如MySQL同一个库下存在 UTF8 和 UTF8MB4 到MogDB只能为UTF8 同步表结构会同步
COLLATE
属性,但是受限于数据库支持的,不支持到变成默认COLLATE. 具体支持列表查看pg_catalog.pg_collation
反向表结构同步会丢失COLLATE
属性. 会导致出现列长度超过65535等问题. 推荐使用源建表语句进行初始化结构
数据库
MTK 迁移 MySQL 的 数据库为 MogDB/openGauss schema. 一定要注意字符集和COLLATE.
MySQL查看 COLLATE
select schema_name,default_character_set_name,DEFAULT_COLLATION_NAME from information_schema.schemata;
MTK 暂时不迁移COLLATE属性,需要人工介入确定好,创建schema 后面版本会不会考虑迁移待定
序列/自增列
MySQL 没有序列. 在不支持列属性 auto_increment
的情况下迁移为目标端序列.
-
不支持 auto_increment
- 兼容模式非B模式.
- 兼容模式B模式未安装插件
dolphin
- 兼容模式B模式并且安装插件
dolphin
,数据库版本小于于3.1.0
-- 创建序列 create sequence sequence_name; -- 指定列默认值为序列next create table table(col col_type default nextval('sequence_name')); -- 修改序列所属者 alter sequence sequence_name owned owner.table_name.column_name -- 修改序列最后值 select setval('',last_number);
-
支持 auto_increment
兼容模式B模式并且安装插件
dolphin
,数据库版本大于3.1.0-- 不创建序列 -- 指定列属性 auto_increment create table table(col col_type auto_increment); -- 修改序列最后值 alter table owner.table_name auto_increment=last_number
表
- 自增列改写为默认值序列
CHARSET
属性移除ENGINE
属性移除
分区表
-
LINEAR Hash
分区迁移为Hash分区 -
LINEAR Key
/Key
分区迁移为Hash分区 -
range partition
-
days 函数 不支持
-
to_days
MySQL
CREATE TABLE mtk.range_part_t1 ( prof_history_id BIGINT(20), person_id BIGINT(20) NOT NULL, organization_id BIGINT(20) NOT NULL, record_date DATETIME NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=UTF8 PARTITION BY RANGE (to_days(record_date)) ( PARTITION yr0 VALUES LESS THAN(736695), PARTITION yr7 VALUES LESS THAN(737060), PARTITION yr8 VALUES LESS THAN(737425), PARTITION yr9 VALUES LESS THAN(MAXVALUE) )
openGauss
CREATE TABLE mtk.range_part_t1 ( prof_history_id BIGINT, person_id BIGINT NOT NULL, organization_id BIGINT NOT NULL, record_date TIMESTAMP NOT NULL ) PARTITION BY RANGE (record_date) ( PARTITION yr0 VALUES LESS THAN('2017-01-01'), PARTITION yr7 VALUES LESS THAN('2018-01-01'), PARTITION yr8 VALUES LESS THAN('2019-01-01'), PARTITION yr9 VALUES LESS THAN(MAXVALUE) )
-
year
MySQL
CREATE TABLE mtk.range_part_t2 ( prof_history_id BIGINT(20), person_id BIGINT(20) NOT NULL, organization_id BIGINT(20) NOT NULL, record_date DATETIME NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=UTF8 PARTITION BY RANGE (year(record_date)) ( PARTITION yr0 VALUES LESS THAN(2018), PARTITION yr7 VALUES LESS THAN(2019), PARTITION yr8 VALUES LESS THAN(2020), PARTITION yr9 VALUES LESS THAN(MAXVALUE) )
openGauss
CREATE TABLE mtk.range_part_t2 ( prof_history_id BIGINT, person_id BIGINT NOT NULL, organization_id BIGINT NOT NULL, record_date TIMESTAMP NOT NULL ) PARTITION BY RANGE (record_date) ( PARTITION yr0 VALUES LESS THAN('2018-01-01'), PARTITION yr7 VALUES LESS THAN('2019-01-01'), PARTITION yr8 VALUES LESS THAN('2020-01-01'), PARTITION yr9 VALUES LESS THAN(MAXVALUE) )
-
unix_timestamp
MySQL
CREATE TABLE mtk1.range_part_t3 ( report_id INT(11) NOT NULL, report_status VARCHAR(20) NOT NULL, report_updated TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP ) ENGINE=InnoDB DEFAULT CHARSET=UTF8 PARTITION BY RANGE (unix_timestamp(report_updated)) ( PARTITION p0 VALUES LESS THAN(1293811200), PARTITION p1 VALUES LESS THAN(1296489600), PARTITION p2 VALUES LESS THAN(1298908800), PARTITION p3 VALUES LESS THAN(1301587200), PARTITION p4 VALUES LESS THAN(1304179200), PARTITION p5 VALUES LESS THAN(1306857600), PARTITION p6 VALUES LESS THAN(1309449600), PARTITION p7 VALUES LESS THAN(1312128000), PARTITION p8 VALUES LESS THAN(1314806400), PARTITION p9 VALUES LESS THAN(MAXVALUE) )
openGauss
CREATE TABLE mtk1.range_part_t3 ( report_id INTEGER NOT NULL, report_status VARCHAR(60) NOT NULL, report_updated TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP ) PARTITION BY RANGE (report_updated) ( -- 1293811200 ---> '2011-01-01 00:00:00' PARTITION p0 VALUES LESS THAN('2011-01-01 00:00:00'), -- 1296489600 ---> '2011-02-01 00:00:00' PARTITION p1 VALUES LESS THAN('2011-02-01 00:00:00'), -- 1298908800 ---> '2011-03-01 00:00:00' PARTITION p2 VALUES LESS THAN('2011-03-01 00:00:00'), -- 1301587200 ---> '2011-04-01 00:00:00' PARTITION p3 VALUES LESS THAN('2011-04-01 00:00:00'), -- 1304179200 ---> '2011-05-01 00:00:00' PARTITION p4 VALUES LESS THAN('2011-05-01 00:00:00'), -- 1306857600 ---> '2011-06-01 00:00:00' PARTITION p5 VALUES LESS THAN('2011-06-01 00:00:00'), -- 1309449600 ---> '2011-07-01 00:00:00' PARTITION p6 VALUES LESS THAN('2011-07-01 00:00:00'), -- 1312128000 ---> '2011-08-01 00:00:00' PARTITION p7 VALUES LESS THAN('2011-08-01 00:00:00'), -- 1314806400 ---> '2011-09-01 00:00:00' PARTITION p8 VALUES LESS THAN('2011-09-01 00:00:00'), PARTITION p9 VALUES LESS THAN(MAXVALUE) )
-
列
列类型映射
MySQL COLUMN_TYPE | openGauss data_type | data_length | data_precision | data_scale | openGauss ex_data_type | Comment |
---|---|---|---|---|---|---|
bit(1) | bool | bool | v2.9.6 | |||
bit(1) | bit(1) | bit(1) | v2.9.5 | |||
bit(2+) | bit(2+) | 2+ | 0 | bit(2+) | ||
bigint(20) | bigint | 64 | 0 | bigint | ||
char(1) | character | 1 | character(1) | |||
varchar(20) | character varying | 20 | character varying(20) | |||
varchar(4000) | character varying | 4000 | character varying(4000) | |||
time | time | time | ||||
date | date | date | ||||
year | int | int | ||||
datetime | timestamp without time zone | timestamp(0) without time zone | ||||
timestamp(6) | timestamp with time zone | timestamp with time zone | ||||
decimal(10,0) | numeric | 10 | 0 | numeric(10,0) | ||
decimal(38,0) | numeric | 38 | 0 | numeric(38,0) | ||
decimal(65,30) | numeric | 65 | 30 | numeric(65,30) | ||
double | DOUBLE PRECISION | DOUBLE PRECISION | ||||
double(10) | numeric | 10 | 5 | numeric(10) | ||
double(10,5) | numeric | 10 | 5 | numeric(10,5) | ||
blob | bytea/blob | bytea/blob | ||||
tinyblob | bytea/blob | bytea/blob | ||||
mediumblob | bytea/blob | bytea/blob | ||||
longblob | bytea/blob | bytea/blob | ||||
tinytext | text | text | ||||
text | text | text | ||||
mediumtext | text | text | ||||
longtext | text | text | ||||
binary(10) | bytea | 10 | bytea | |||
varbinary(10) | bytea | 40 | bytea | |||
enum | enum type | enum type | ||||
set | varchar | varchar | ||||
Geometry | varchar/Geometry | varchar/Geometry | ||||
GeometryCollection | varchar/Geometry | varchar/Geometry | ||||
GemoCollection | varchar/Geometry | varchar/Geometry | ||||
LineString | varchar/Geometry | varchar/Geometry | ||||
MultiPoint | varchar/Geometry | varchar/Geometry | ||||
MultiPolygon | varchar/Geometry | varchar/Geometry | ||||
Point | varchar/Geometry | varchar/Geometry | ||||
Polygon | varchar/Geometry | varchar/Geometry | ||||
MultilineString | varchar/Geometry | varchar/Geometry |
- MySQL
bigint unsigned
自增列迁移到 openGauss 需要注意序列大小 - 字段长度会根据迁移到openGauss的兼容模式进行扩充
- timestamp列默认值为
0000-00-00 00:00:00
修改为1970-01-01
Spatial Data Type
MTK 2.5.3 支持. 如果安装 Postgis
迁移为geomotry
,否则为varchar
.
支持以下类型: + Geometry + GeometryCollection + LineString + MultiPoint + MultiPolygon + Point + Polygon + MultilineString
Set
MySQL Set类型可以插入多个值,暂时迁移到openGauss varchar 类型
数据
-
时间列数据为
0000-00-00 13:14:13
这种数据在openGauss不支持可通过参数mySQLSkipErrorDateTimeData or igErrorData 忽略
约束
-
在openGauss/MogDB端会自动改名
-
不支持子表的外键指向父表的非唯一索引
CREATE TABLE `t1` ( `id` int(11) NOT NULL, `uuid` binary(16) NOT NULL COMMENT 'UUID', PRIMARY KEY (`id`) USING BTREE, KEY `uuid` (`uuid`) USING BTREE ); CREATE TABLE `t2` ( `c1_uuid` binary(16) NOT NUL, `c2_uuid` binary(16) NOT NULL, PRIMARY KEY (`c1_uuid`,`c2_uuid`), CONSTRAINT `FK_T1` FOREIGN KEY (`c2_uuid`) REFERENCES `t1` (`uuid`) ON DELETE RESTRICT ON UPDATE RESTRICT ); -- FK_T1 约束不会迁移. 它指向的依赖是普通索引
索引
- 在openGauss/MogDB端会自动改名
- 索引分区暂时不支持