使用手册

    权限要求

    1. 源端开启

    MySQL 5.7 my.cnf 示例配置:

    执行以下命令,确认是否有开启 binlog:

    1. show variables like '%log_bin%';
    2. show variables like '%binlog%';

    如以下显示,则说明 binlog 已开启

    1. +-----------------------------------------+---------------------------------------+
    2. | Variable_name | Value |
    3. +-----------------------------------------+---------------------------------------+
    4. | log_bin | ON |
    5. | binlog_format | ROW |
    6. | binlog_row_image | FULL |
    7. +-----------------------------------------+---------------------------------------+
    1. 赋予源端 MySQL 账号 replication 相关权限。

    执行以下命令,查看该用户是否有迁移权限:

    1. SHOW GRANTS FOR 'migration_user';

    示例结果:

    1. +------------------------------------------------------------------------------+
    2. |Grants for ${username}@${host} |
    3. +------------------------------------------------------------------------------+
    4. |GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO ${username}@${host} |
    5. |....... |
    6. +------------------------------------------------------------------------------+
    1. 赋予 MySQL 账号 DDL DML 权限

    源端账号需要具备查询权限。 示例:

    1. GRANT SELECT ON migration_ds_0.* TO `migration_user`@`%`;

    目标端账号需要具备增删改查等权限。 示例:

    1. GRANT CREATE, DROP, INDEX, SELECT, INSERT, UPDATE, DELETE ON *.* TO `migration_user`@`%`;

    详情请参见

    完整流程示例

    前提条件

    1. 在 MySQL 已准备好源端库、表、数据。
    1. DROP DATABASE IF EXISTS migration_ds_0;
    2. CREATE DATABASE migration_ds_0 DEFAULT CHARSET utf8;
    3. USE migration_ds_0;
    4. CREATE TABLE t_order (order_id INT NOT NULL, user_id INT NOT NULL, status VARCHAR(45) NULL, PRIMARY KEY (order_id));
    5. INSERT INTO t_order (order_id, user_id, status) VALUES (1,2,'ok'),(2,4,'ok'),(3,6,'ok'),(4,1,'ok'),(5,3,'ok'),(6,5,'ok');
    1. 在 MySQL 准备目标端库。
    1. DROP DATABASE IF EXISTS migration_ds_10;
    2. CREATE DATABASE migration_ds_10 DEFAULT CHARSET utf8;
    3. DROP DATABASE IF EXISTS migration_ds_11;
    4. CREATE DATABASE migration_ds_11 DEFAULT CHARSET utf8;
    5. DROP DATABASE IF EXISTS migration_ds_12;
    6. CREATE DATABASE migration_ds_12 DEFAULT CHARSET utf8;

    操作步骤

    1. 在 proxy 新建逻辑数据库并配置好存储单元和规则。
    1. CREATE DATABASE sharding_db;
    2. USE sharding_db
    3. REGISTER STORAGE UNIT ds_2 (
    4. URL="jdbc:mysql://127.0.0.1:3306/migration_ds_10?serverTimezone=UTC&useSSL=false",
    5. USER="root",
    6. PASSWORD="root",
    7. PROPERTIES("minPoolSize"="1","maxPoolSize"="20","idleTimeout"="60000")
    8. ), ds_3 (
    9. URL="jdbc:mysql://127.0.0.1:3306/migration_ds_11?serverTimezone=UTC&useSSL=false",
    10. USER="root",
    11. PASSWORD="root",
    12. PROPERTIES("minPoolSize"="1","maxPoolSize"="20","idleTimeout"="60000")
    13. ), ds_4 (
    14. URL="jdbc:mysql://127.0.0.1:3306/migration_ds_12?serverTimezone=UTC&useSSL=false",
    15. USER="root",
    16. PASSWORD="root",
    17. PROPERTIES("minPoolSize"="1","maxPoolSize"="20","idleTimeout"="60000")
    18. );
    19. CREATE SHARDING TABLE RULE t_order(
    20. STORAGE_UNITS(ds_2,ds_3,ds_4),
    21. SHARDING_COLUMN=order_id,
    22. TYPE(NAME="hash_mod",PROPERTIES("sharding-count"="6")),
    23. KEY_GENERATE_STRATEGY(COLUMN=order_id,TYPE(NAME="snowflake"))
    24. );

    如果是迁移到异构数据库,那目前需要在 proxy 执行建表语句。

    1. 在 proxy 配置源端存储单元。
    1. REGISTER MIGRATION SOURCE STORAGE UNIT ds_0 (
    2. URL="jdbc:mysql://127.0.0.1:3306/migration_ds_0?serverTimezone=UTC&useSSL=false",
    3. USER="root",
    4. PASSWORD="root",
    5. PROPERTIES("minPoolSize"="1","maxPoolSize"="20","idleTimeout"="60000")
    6. );
    1. 启动数据迁移。
    1. MIGRATE TABLE ds_0.t_order INTO t_order;

    或者指定目标端逻辑库:

    1. MIGRATE TABLE ds_0.t_order INTO sharding_db.t_order;
    1. 查看数据迁移作业列表。
    1. SHOW MIGRATION LIST;

    示例结果:

    1. +---------------------------------------+---------+----------------------+--------+---------------------+-----------+
    2. | id | tables | job_item_count | active | create_time | stop_time |
    3. +---------------------------------------+---------+----------------------+--------+---------------------+-----------+
    4. | j01016e501b498ed1bdb2c373a2e85e2529a6 | t_order | 1 | true | 2022-10-13 11:16:01 | NULL |
    5. +---------------------------------------+---------+----------------------+--------+---------------------+-----------+
    1. 查看数据迁移详情。
    1. SHOW MIGRATION STATUS 'j01016e501b498ed1bdb2c373a2e85e2529a6';

    示例结果:

    1. +------+-------------+--------------------------+--------+-------------------------+-------------------------------+--------------------------+---------------+
    2. | item | data_source | status | active | processed_records_count | inventory_finished_percentage | incremental_idle_seconds | error_message |
    3. +------+-------------+--------------------------+--------+-------------------------+-------------------------------+--------------------------+---------------+
    4. | 0 | ds_0 | EXECUTE_INCREMENTAL_TASK | true | 6 | 100 | 81 | |
    5. +------+-------------+--------------------------+--------+-------------------------+-------------------------------+--------------------------+---------------+
    1. 执行数据一致性校验。

      数据一致性校验算法类型来自:

      1. SHOW MIGRATION CHECK ALGORITHMS;

      示例结果:

      1. +-------------+--------------------------------------------------------------+----------------------------+
      2. | type | supported_database_types | description |
      3. +-------------+--------------------------------------------------------------+----------------------------+
      4. | CRC32_MATCH | MySQL | Match CRC32 of records. |
      5. | DATA_MATCH | SQL92,MySQL,MariaDB,PostgreSQL,openGauss,Oracle,SQLServer,H2 | Match raw data of records. |
      6. +-------------+--------------------------------------------------------------+----------------------------+

      目标端开启数据加密的情况需要使用DATA_MATCH

      异构迁移需要使用DATA_MATCH

      查询数据一致性校验进度:

      1. SHOW MIGRATION CHECK STATUS 'j01016e501b498ed1bdb2c373a2e85e2529a6';

      示例结果:

      1. +---------+--------+---------------------+-------------------+-------------------------+-------------------------+------------------+---------------+
      2. | t_order | true | 100 | 0 | 2022-10-13 11:18:15.171 | 2022-10-13 11:18:15.878 | 0 | |
      3. +---------+--------+---------------------+-------------------+-------------------------+-------------------------+------------------+---------------+
      1. 完成作业。
      1. COMMIT MIGRATION 'j01016e501b498ed1bdb2c373a2e85e2529a6';
      1. 刷新元数据。

      更多 DistSQL 请参见 。

      支持的 PostgreSQL 版本:9.4 或以上版本。

      权限要求

      1. 源端开启 。

      2. 源端调整 WAL 配置。

      1. wal_level = logical
      2. max_wal_senders = 10
      3. max_replication_slots = 10
      4. wal_sender_timeout = 0
      5. max_connections = 600

      详情请参见 Write Ahead Log 和 。

      1. 赋予源端 PostgreSQL 账号 replication 权限。

      pg_hba.conf 示例配置:

      1. host replication repl_acct 0.0.0.0/0 md5

      详情请参见 The pg_hba.conf File

      1. 赋予源端 PostgreSQL 账号 DDL DML 权限。

      如果使用非超级管理员账号进行迁移,要求该账号在迁移时用到的数据库上,具备 CREATE 和 CONNECT 的权限。

      示例:

      1. GRANT CREATE, CONNECT ON DATABASE migration_ds_0 TO migration_user;

      还需要账号对迁移的表和 schema 具备访问权限,以 test schema 下的 t_order 表为例。

      1. \c migration_ds_0
      2. GRANT USAGE ON SCHEMA test TO GROUP migration_user;
      3. GRANT SELECT ON TABLE test.t_order TO migration_user;

      PostgreSQL 有 OWNER 的概念,如果是数据库,SCHEMA,表的 OWNER,则可以省略对应的授权步骤。

      详情请参见

      完整流程示例

      前提条件

      1. 在 PostgreSQL 已准备好源端库、表、数据。
      1. DROP DATABASE IF EXISTS migration_ds_0;
      2. CREATE DATABASE migration_ds_0;
      3. \c migration_ds_0
      4. CREATE TABLE t_order (order_id INT NOT NULL, user_id INT NOT NULL, status VARCHAR(45) NULL, PRIMARY KEY (order_id));
      5. INSERT INTO t_order (order_id, user_id, status) VALUES (1,2,'ok'),(2,4,'ok'),(3,6,'ok'),(4,1,'ok'),(5,3,'ok'),(6,5,'ok');
      1. 在 PostgreSQL 准备目标端库。
      1. DROP DATABASE IF EXISTS migration_ds_10;
      2. CREATE DATABASE migration_ds_10;
      3. DROP DATABASE IF EXISTS migration_ds_11;
      4. CREATE DATABASE migration_ds_11;
      5. DROP DATABASE IF EXISTS migration_ds_12;
      6. CREATE DATABASE migration_ds_12;

      操作步骤

      1. 在 proxy 新建逻辑数据库并配置好存储单元和规则。
      1. CREATE DATABASE sharding_db;
      2. \c sharding_db
      3. REGISTER STORAGE UNIT ds_2 (
      4. URL="jdbc:postgresql://127.0.0.1:5432/migration_ds_10",
      5. USER="postgres",
      6. PASSWORD="root",
      7. PROPERTIES("minPoolSize"="1","maxPoolSize"="20","idleTimeout"="60000")
      8. ), ds_3 (
      9. URL="jdbc:postgresql://127.0.0.1:5432/migration_ds_11",
      10. USER="postgres",
      11. PASSWORD="root",
      12. PROPERTIES("minPoolSize"="1","maxPoolSize"="20","idleTimeout"="60000")
      13. ), ds_4 (
      14. URL="jdbc:postgresql://127.0.0.1:5432/migration_ds_12",
      15. USER="postgres",
      16. PASSWORD="root",
      17. PROPERTIES("minPoolSize"="1","maxPoolSize"="20","idleTimeout"="60000")
      18. );
      19. CREATE SHARDING TABLE RULE t_order(
      20. STORAGE_UNITS(ds_2,ds_3,ds_4),
      21. SHARDING_COLUMN=order_id,
      22. TYPE(NAME="hash_mod",PROPERTIES("sharding-count"="6")),
      23. KEY_GENERATE_STRATEGY(COLUMN=order_id,TYPE(NAME="snowflake"))
      24. );

      如果是迁移到异构数据库,那目前需要在 proxy 执行建表语句。

      1. 在 proxy 配置源端存储单元。
      1. REGISTER MIGRATION SOURCE STORAGE UNIT ds_0 (
      2. URL="jdbc:postgresql://127.0.0.1:5432/migration_ds_0",
      3. USER="postgres",
      4. PASSWORD="root",
      5. PROPERTIES("minPoolSize"="1","maxPoolSize"="20","idleTimeout"="60000")
      6. );
      1. 启动数据迁移。
      1. MIGRATE TABLE ds_0.t_order INTO t_order;

      或者指定目标端逻辑库:

      1. MIGRATE TABLE ds_0.t_order INTO sharding_db.t_order;

      也可以指定源端schema:

      1. MIGRATE TABLE ds_0.public.t_order INTO sharding_db.t_order;
      1. 查看数据迁移作业列表。
      1. SHOW MIGRATION LIST;

      示例结果:

      1. +---------------------------------------+---------+----------------------+--------+---------------------+-----------+
      2. | id | tables | job_item_count | active | create_time | stop_time |
      3. +---------------------------------------+---------+----------------------+--------+---------------------+-----------+
      4. | j01016e501b498ed1bdb2c373a2e85e2529a6 | t_order | 1 | true | 2022-10-13 11:16:01 | NULL |
      5. +---------------------------------------+---------+----------------------+--------+---------------------+-----------+
      1. 查看数据迁移详情。
      1. SHOW MIGRATION STATUS 'j01016e501b498ed1bdb2c373a2e85e2529a6';

      示例结果:

      1. +------+-------------+--------------------------+--------+-------------------------+-------------------------------+--------------------------+---------------+
      2. | item | data_source | status | active | processed_records_count | inventory_finished_percentage | incremental_idle_seconds | error_message |
      3. +------+-------------+--------------------------+--------+-------------------------+-------------------------------+--------------------------+---------------+
      4. | 0 | ds_0 | EXECUTE_INCREMENTAL_TASK | true | 6 | 100 | 81 | |
      5. +------+-------------+--------------------------+--------+-------------------------+-------------------------------+--------------------------+---------------+
      1. 执行数据一致性校验。
      1. CHECK MIGRATION 'j01016e501b498ed1bdb2c373a2e85e2529a6';

      查询数据一致性校验进度:

      1. SHOW MIGRATION CHECK STATUS 'j01016e501b498ed1bdb2c373a2e85e2529a6';

      示例结果:

      1. +---------+--------+---------------------+-------------------+-------------------------+-------------------------+------------------+---------------+
      2. | tables | result | finished_percentage | remaining_seconds | check_begin_time | check_end_time | duration_seconds | error_message |
      3. +---------+--------+---------------------+-------------------+-------------------------+-------------------------+------------------+---------------+
      4. | t_order | true | 100 | 0 | 2022-10-13 11:18:15.171 | 2022-10-13 11:18:15.878 | 0 | |
      5. +---------+--------+---------------------+-------------------+-------------------------+-------------------------+------------------+---------------+
      1. 完成作业。
        1. 刷新元数据。
        1. REFRESH TABLE METADATA;

        更多 DistSQL 请参见 。

        支持的 openGauss 版本:2.0.1 ~ 3.0.0。

        权限要求

        1. 调整源端 WAL 配置。

        postgresql.conf 示例配置:

        1. wal_level = logical
        2. max_wal_senders = 10
        3. wal_sender_timeout = 0
        4. max_connections = 600

        详情请参见 和 Replication

        1. 赋予源端 openGauss 账号 replication 权限。

        pg_hba.conf 示例配置:

        1. host replication repl_acct 0.0.0.0/0 md5

        详情请参见 和 Example: Logic Replication Code

        1. 赋予 openGauss 账号 DDL DML 权限。

        如果使用非超级管理员账号进行迁移,要求该账号在迁移时用到的数据库上,具备 CREATE 和 CONNECT 的权限。

        还需要账号对迁移的表和 schema 具备访问权限,以 test schema 下的 t_order 表为例。

        1. \c migration_ds_0
        2. GRANT USAGE ON SCHEMA test TO GROUP migration_user;
        3. GRANT SELECT ON TABLE test.t_order TO migration_user;

        openGauss 有 OWNER 的概念,如果是数据库,SCHEMA,表的 OWNER,则可以省略对应的授权步骤。

        openGauss 不允许普通账户在 public schema 下操作。所以如果迁移的表在 public schema 下,需要额外授权。

        1. GRANT ALL PRIVILEGES TO migration_user;

        详情请参见

        完整流程示例

        前提条件

        1. 准备好源端库、表、数据。

        1.1. 同构数据库。

        1. DROP DATABASE IF EXISTS migration_ds_0;
        2. CREATE DATABASE migration_ds_0;
        3. \c migration_ds_0
        4. CREATE TABLE t_order (order_id INT NOT NULL, user_id INT NOT NULL, status VARCHAR(45) NULL, PRIMARY KEY (order_id));
        5. INSERT INTO t_order (order_id, user_id, status) VALUES (1,2,'ok'),(2,4,'ok'),(3,6,'ok'),(4,1,'ok'),(5,3,'ok'),(6,5,'ok');

        1.2. 异构数据库。

        MySQL 示例:

        1. DROP DATABASE IF EXISTS migration_ds_0;
        2. CREATE DATABASE migration_ds_0 DEFAULT CHARSET utf8;
        3. USE migration_ds_0;
        4. CREATE TABLE t_order (order_id INT NOT NULL, user_id INT NOT NULL, status VARCHAR(45) NULL, PRIMARY KEY (order_id));
        5. INSERT INTO t_order (order_id, user_id, status) VALUES (1,2,'ok'),(2,4,'ok'),(3,6,'ok'),(4,1,'ok'),(5,3,'ok'),(6,5,'ok');
        1. 在 openGauss 准备目标端库。
        1. DROP DATABASE IF EXISTS migration_ds_10;
        2. CREATE DATABASE migration_ds_10;
        3. DROP DATABASE IF EXISTS migration_ds_11;
        4. CREATE DATABASE migration_ds_11;
        5. DROP DATABASE IF EXISTS migration_ds_12;
        6. CREATE DATABASE migration_ds_12;

        操作步骤

        1. 在 proxy 新建逻辑数据库并配置好存储单元和规则。

        1.1. 创建逻辑库。

        1. CREATE DATABASE sharding_db;
        2. \c sharding_db

        1.2. 注册存储单元。

        1. REGISTER STORAGE UNIT ds_2 (
        2. URL="jdbc:opengauss://127.0.0.1:5432/migration_ds_10",
        3. USER="gaussdb",
        4. PASSWORD="Root@123",
        5. PROPERTIES("minPoolSize"="1","maxPoolSize"="20","idleTimeout"="60000")
        6. ), ds_3 (
        7. URL="jdbc:opengauss://127.0.0.1:5432/migration_ds_11",
        8. USER="gaussdb",
        9. PASSWORD="Root@123",
        10. PROPERTIES("minPoolSize"="1","maxPoolSize"="20","idleTimeout"="60000")
        11. ), ds_4 (
        12. URL="jdbc:opengauss://127.0.0.1:5432/migration_ds_12",
        13. USER="gaussdb",
        14. PASSWORD="Root@123",
        15. PROPERTIES("minPoolSize"="1","maxPoolSize"="20","idleTimeout"="60000")
        16. );

        1.3. 创建分片规则。

        1. CREATE SHARDING TABLE RULE t_order(
        2. STORAGE_UNITS(ds_2,ds_3,ds_4),
        3. SHARDING_COLUMN=order_id,
        4. TYPE(NAME="hash_mod",PROPERTIES("sharding-count"="6")),
        5. KEY_GENERATE_STRATEGY(COLUMN=order_id,TYPE(NAME="snowflake"))
        6. );

        1.4. 创建目标端表。

        如果是迁移到异构数据库,那目前需要在 proxy 执行建表语句。

        1. CREATE TABLE t_order (order_id INT NOT NULL, user_id INT NOT NULL, status VARCHAR(45) NULL, PRIMARY KEY (order_id));
        1. 在 proxy 配置源端存储单元。

        2.1. 同构数据库。

        1. REGISTER MIGRATION SOURCE STORAGE UNIT ds_0 (
        2. URL="jdbc:opengauss://127.0.0.1:5432/migration_ds_0",
        3. USER="gaussdb",
        4. PASSWORD="Root@123",
        5. PROPERTIES("minPoolSize"="1","maxPoolSize"="20","idleTimeout"="60000")
        6. );

        2.2. 异构数据库。

        MySQL 示例:

        1. REGISTER MIGRATION SOURCE STORAGE UNIT ds_0 (
        2. URL="jdbc:mysql://127.0.0.1:3306/migration_ds_0?serverTimezone=UTC&useSSL=false",
        3. USER="root",
        4. PASSWORD="root",
        5. PROPERTIES("minPoolSize"="1","maxPoolSize"="20","idleTimeout"="60000")
        6. );
        1. 启动数据迁移。
        1. MIGRATE TABLE ds_0.t_order INTO t_order;

        或者指定目标端逻辑库:

        1. MIGRATE TABLE ds_0.t_order INTO sharding_db.t_order;

        也可以指定源端schema:

        1. MIGRATE TABLE ds_0.public.t_order INTO sharding_db.t_order;
        1. 查看数据迁移作业列表。
        1. SHOW MIGRATION LIST;

        示例结果:

        1. +---------------------------------------+---------+----------------------+--------+---------------------+-----------+
        2. | id | tables | job_item_count | active | create_time | stop_time |
        3. +---------------------------------------+---------+----------------------+--------+---------------------+-----------+
        4. | j01016e501b498ed1bdb2c373a2e85e2529a6 | t_order | 1 | true | 2022-10-13 11:16:01 | NULL |
        5. +---------------------------------------+---------+----------------------+--------+---------------------+-----------+
        1. 查看数据迁移详情。
        1. SHOW MIGRATION STATUS 'j01016e501b498ed1bdb2c373a2e85e2529a6';

        示例结果:

        1. +------+-------------+--------------------------+--------+-------------------------+-------------------------------+--------------------------+---------------+
        2. | item | data_source | status | active | processed_records_count | inventory_finished_percentage | incremental_idle_seconds | error_message |
        3. +------+-------------+--------------------------+--------+-------------------------+-------------------------------+--------------------------+---------------+
        4. | 0 | ds_0 | EXECUTE_INCREMENTAL_TASK | true | 6 | 100 | 81 | |
        5. +------+-------------+--------------------------+--------+-------------------------+-------------------------------+--------------------------+---------------+
        1. 执行数据一致性校验。
        1. CHECK MIGRATION 'j01016e501b498ed1bdb2c373a2e85e2529a6';

        查询数据一致性校验进度:

        1. SHOW MIGRATION CHECK STATUS 'j01016e501b498ed1bdb2c373a2e85e2529a6';

        示例结果:

        1. +---------+--------+---------------------+-------------------+-------------------------+-------------------------+------------------+---------------+
        2. | tables | result | finished_percentage | remaining_seconds | check_begin_time | check_end_time | duration_seconds | error_message |
        3. +---------+--------+---------------------+-------------------+-------------------------+-------------------------+------------------+---------------+
        4. | t_order | true | 100 | 0 | 2022-10-13 11:18:15.171 | 2022-10-13 11:18:15.878 | 0 | |
        5. +---------+--------+---------------------+-------------------+-------------------------+-------------------------+------------------+---------------+
        1. 完成作业。

        更多 DistSQL 请参见 。