OBCP实践 - 迁移 MySQL 数据到 OceanBase 集群

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介: OBCP实践 - 迁移MySQL数据到OceanBase集群,这是一个涉及到将现有MySQL数据库的数据和表结构迁移到OceanBase分布式数据库集群的实际操作过程。OceanBase是一款高度兼容MySQL协议的分布式数据库产品,支持在线平滑迁移,以便企业用户可以从传统的MySQL数据库平滑迁移到OceanBase,以实现更高的可用性、扩展性和性能。

1、mysql导出数据且SCPob数据库上

mysql> show tables;

+------------------------+

| Tables_in_psd_schedule |

+------------------------+

| pf_td_ext_data_dict    |

| pf_td_simple_triggers  |

| pf_td_triggers         |

+------------------------+

3 rows in set (0.09 sec)

 

mysql> select count(1) from pf_td_ext_data_dict;

+----------+

| count(1) |

+----------+

|       23 |

+----------+

1 row in set (0.35 sec)

 

mysql> select count(1) from  pf_td_simple_triggers;

+----------+

| count(1) |

+----------+

|      685 |

+----------+

1 row in set (0.48 sec)

 

mysql> select count(1) from pf_td_triggers;

+----------+

| count(1) |

+----------+

|      843 |

+----------+

1 row in set (0.93 sec)

[root@mongdb2 ~]# mysqldump -uroot -p psd_schedule>schedule.sql

Enter password:

Warning: A partial dump from a server that has GTIDs will by default include the GTIDs of all transactions, even those that changed suppressed parts of the database. If you don't want to restore GTIDs, pass --set-gtid-purged=OFF. To make a complete dump, pass --all-databases --triggers --routines --events.

[root@mongdb2 ~]# more psd_schedule.sql

 

 scp schedule.sql  admin@xxx:/u01

2、Oceanbase数据库导入到test租户TEST数据库中

obclient [test]> source /u01/psd_schedule.sql

Query OK, 0 rows affected (0.009 sec)

 

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your OceanBase version for the right syntax to use near '--' at line 1

Query OK, 0 rows affected (0.009 sec)

 

Query OK, 0 rows affected (0.013 sec)

 

Query OK, 0 rows affected (0.009 sec)

 

Query OK, 0 rows affected (0.011 sec)

 

Query OK, 0 rows affected (0.010 sec)

 

Query OK, 0 rows affected (0.010 sec)

 

Query OK, 0 rows affected (0.010 sec)

 

Query OK, 0 rows affected (0.010 sec)

 

Query OK, 0 rows affected (0.001 sec)

 

Query OK, 0 rows affected (0.009 sec)

 

Query OK, 0 rows affected (0.001 sec)

 

Query OK, 0 rows affected (0.009 sec)

 

Query OK, 0 rows affected (0.002 sec)

 

ERROR 1193 (HY000): Unknown system variable 'SQL_LOG_BIN'

ERROR 1193 (HY000): Unknown system variable 'sql_log_bin'

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your OceanBase version for the right syntax to use near '--' at line 1

Query OK, 0 rows affected (0.010 sec)

 

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your OceanBase version for the right syntax to use near '--' at line 1

ERROR 1193 (HY000): Unknown system variable 'gtid_purged'

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your OceanBase version for the right syntax to use near '--' at line 1

Query OK, 0 rows affected (0.004 sec)

 

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your OceanBase version for the right syntax to use near '--' at line 1

Query OK, 0 rows affected, 1 warning (0.039 sec)

 

Query OK, 0 rows affected (0.007 sec)

 

Query OK, 0 rows affected (0.003 sec)

 

Query OK, 0 rows affected, 1 warning (0.996 sec)

 

Query OK, 0 rows affected (0.011 sec)

 

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your OceanBase version for the right syntax to use near '--' at line 1

Query OK, 0 rows affected (0.010 sec)

 

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your OceanBase version for the right syntax to use near '--' at line 1

Query OK, 0 rows affected (0.006 sec)

 

Query OK, 0 rows affected (0.013 sec)

 

Query OK, 23 rows affected (1.543 sec)

Records: 23  Duplicates: 0  Warnings: 0

 

Query OK, 0 rows affected (0.017 sec)

 

Query OK, 0 rows affected (0.011 sec)

 

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your OceanBase version for the right syntax to use near '--' at line 1

Query OK, 0 rows affected (0.013 sec)

 

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your OceanBase version for the right syntax to use near '--' at line 1

Query OK, 0 rows affected, 1 warning (0.029 sec)

 

Query OK, 0 rows affected (0.011 sec)

 

Query OK, 0 rows affected (0.010 sec)

 

Query OK, 0 rows affected, 1 warning (0.218 sec)

 

Query OK, 0 rows affected (0.022 sec)

 

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your OceanBase version for the right syntax to use near '--' at line 1

Query OK, 0 rows affected (0.007 sec)

 

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your OceanBase version for the right syntax to use near '--' at line 1

Query OK, 0 rows affected (0.011 sec)

 

Query OK, 0 rows affected (0.014 sec)

 

Query OK, 685 rows affected (0.157 sec)

Records: 685  Duplicates: 0  Warnings: 0

 

Query OK, 0 rows affected (0.004 sec)

 

Query OK, 0 rows affected (0.006 sec)

 

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your OceanBase version for the right syntax to use near '--' at line 1

Query OK, 0 rows affected (0.022 sec)

 

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your OceanBase version for the right syntax to use near '--' at line 1

Query OK, 0 rows affected, 1 warning (0.007 sec)

 

Query OK, 0 rows affected (0.002 sec)

 

Query OK, 0 rows affected (0.009 sec)

 

Query OK, 0 rows affected, 1 warning (0.674 sec)

 

Query OK, 0 rows affected (0.007 sec)

 

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your OceanBase version for the right syntax to use near '--' at line 1

Query OK, 0 rows affected (0.007 sec)

 

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your OceanBase version for the right syntax to use near '--' at line 1

Query OK, 0 rows affected (0.008 sec)

 

Query OK, 0 rows affected (0.003 sec)

 

Query OK, 843 rows affected (1.353 sec)

Records: 843  Duplicates: 0  Warnings: 0

 

Query OK, 0 rows affected (0.015 sec)

 

Query OK, 0 rows affected (0.009 sec)

 

ERROR 1193 (HY000): Unknown system variable 'sql_log_bin'

Query OK, 0 rows affected (0.010 sec)

 

Query OK, 0 rows affected (0.011 sec)

 

Query OK, 0 rows affected (0.023 sec)

 

Query OK, 0 rows affected (0.006 sec)

 

Query OK, 0 rows affected (0.011 sec)

 

Query OK, 0 rows affected (0.006 sec)

 

Query OK, 0 rows affected (0.010 sec)

 

Query OK, 0 rows affected (0.009 sec)

 

Query OK, 0 rows affected (0.014 sec)

 

obclient [test]> show tables;

+-----------------------+

| Tables_in_test        |

+-----------------------+

| pf_td_ext_data_dict   |

| pf_td_simple_triggers |

| pf_td_triggers        |

+-----------------------+

3 rows in set (0.017 sec)

 

obclient [test]> select count(1) from pf_td_ext_data_dict;

+----------+

| count(1) |

+----------+

|       23 |

+----------+

1 row in set (0.009 sec)

 

obclient [test]> select count(1) from pf_td_simple_triggers;

+----------+

| count(1) |

+----------+

|      685 |

+----------+

1 row in set (0.011 sec)

 

obclient [test]> select count(1) from pf_td_triggers;

+----------+

| count(1) |

+----------+

|      843 |

+----------+

1 row in set (0.019 sec)

有些兼容性的报错,数据全部导入完成。

3、部署DATAX软件

下载地址:http://datax-opensource.oss-cn-hangzhou.aliyuncs.com/datax.tar.gz

解压软件:

tar -xvf  datax.tar.gz -C /tmp

生存配置样例:

python ./datax/bin/datax.py -r mysqlreader -w oceanbasev10writer > rds2ob1.json

 

修改rds2ob1.json文件

{

    "job": {

        "setting": {

            "speed": {

                 "channel":4

            },

                 "errorLimit": {

                         "record": 1

                 }

        },

        "content": [

            {

                "reader": {

                    "name": "mysqlreader",

                    "parameter": {

                        "username": "root",

                        "password": "123456",

                         "column": ["*"],

                        "connection": [

                            {

                                "jdbcUrl": [

                                          "jdbc:mysql://xxxx:3306/psd_schedule?useUnicode=true&characterEncoding=utf8&autoReconnect=true&serverTimezone=Asia/Shanghai"

                                  ],

                                  "table": ["pf_td_triggers"]

                            }

                        ]

                    }

                },

                 "writer": {

                    "name": "oceanbasev10writer",

                    "parameter": {

                        "writeMode": "replace",

                        "username": "root",

                        "password": "xxxx",

                         "column": ["*"],

                         "batchSize": 1024,

                        "connection": [

                            {

                                "jdbcUrl": "||_dsc_ob10_dsc_||obtest:test||_dsc_ob10_dsc_||jdbc:oceanbase://xxxx:2883/trade?useLocalSessionState=true&allowBatch=true&allowMultiQueries=true&rewriteBatchedStatements=true",

                                  "table": ["pf_td_triggers"]

                            }

                        ]

                    }

                }

            }

        ]

    }

}

标红部分obtest是集群名,test是租户名。tradeDB名字

执行离线同步运行 python ./datax/bin/datax.py rds2ob1.json 即可不落地文件,同步数据到OceanBase中。结果如下:

image.png

核实OCEANBASE test租户trade数据库中的数据是否同步:

[admin@ob ~]$ obclient  -h172.22.150.7 -P2883 -p -A -c -Dtest -uroot@test

Enter password:

Welcome to the OceanBase.  Commands end with ; or \g.

Your OceanBase connection id is 33

Server version: OceanBase 3.1.0 (r-) (Built May 30 2021 11:21:29)

 

Copyright (c) 2000, 2018, OceanBase and/or its affiliates. All rights reserved.

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

obclient [test]>

obclient [test]>

obclient [test]> show databases;

+--------------------+

| Database           |

+--------------------+

| oceanbase          |

| information_schema |

| mysql              |

| test               |

| trade              |

+--------------------+

5 rows in set (0.013 sec)

 

obclient [test]> use trade;

Database changed

obclient [trade]> show tables;

+-----------------+

| Tables_in_trade |

+-----------------+

| emp             |

| pf_td_triggers  |

+-----------------+

2 rows in set (0.012 sec)

 

obclient [trade]> select count(1) from pf_td_triggers;

+----------+

| count(1) |

+----------+

|      843 |

+----------+

1 row in set (0.026 sec)

 

相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
1天前
|
SQL 资源调度 关系型数据库
实时计算 Flink版产品使用合集之在抓取 MySQL binlog 数据时,datetime 字段会被自动转换为时间戳形式如何解决
实时计算Flink版作为一种强大的流处理和批处理统一的计算框架,广泛应用于各种需要实时数据处理和分析的场景。实时计算Flink版通常结合SQL接口、DataStream API、以及与上下游数据源和存储系统的丰富连接器,提供了一套全面的解决方案,以应对各种实时计算需求。其低延迟、高吞吐、容错性强的特点,使其成为众多企业和组织实时数据处理首选的技术平台。以下是实时计算Flink版的一些典型使用合集。
9 2
|
2天前
|
关系型数据库 MySQL 数据库
实时计算 Flink版产品使用合集之支持将数据写入 OceanBase 数据库吗
实时计算Flink版作为一种强大的流处理和批处理统一的计算框架,广泛应用于各种需要实时数据处理和分析的场景。实时计算Flink版通常结合SQL接口、DataStream API、以及与上下游数据源和存储系统的丰富连接器,提供了一套全面的解决方案,以应对各种实时计算需求。其低延迟、高吞吐、容错性强的特点,使其成为众多企业和组织实时数据处理首选的技术平台。以下是实时计算Flink版的一些典型使用合集。
19 5
|
2天前
|
关系型数据库 MySQL API
实时计算 Flink版产品使用合集之可以通过mysql-cdc动态监听MySQL数据库的数据变动吗
实时计算Flink版作为一种强大的流处理和批处理统一的计算框架,广泛应用于各种需要实时数据处理和分析的场景。实时计算Flink版通常结合SQL接口、DataStream API、以及与上下游数据源和存储系统的丰富连接器,提供了一套全面的解决方案,以应对各种实时计算需求。其低延迟、高吞吐、容错性强的特点,使其成为众多企业和组织实时数据处理首选的技术平台。以下是实时计算Flink版的一些典型使用合集。
16 0
|
2天前
|
消息中间件 关系型数据库 MySQL
实时计算 Flink版产品使用合集之2.2.1版本同步mysql数据写入doris2.0 ,同步完了之后增量的数据延迟能达到20分钟甚至一直不写入如何解决
实时计算Flink版作为一种强大的流处理和批处理统一的计算框架,广泛应用于各种需要实时数据处理和分析的场景。实时计算Flink版通常结合SQL接口、DataStream API、以及与上下游数据源和存储系统的丰富连接器,提供了一套全面的解决方案,以应对各种实时计算需求。其低延迟、高吞吐、容错性强的特点,使其成为众多企业和组织实时数据处理首选的技术平台。以下是实时计算Flink版的一些典型使用合集。
11 1
|
2天前
|
Oracle 关系型数据库 MySQL
实时计算 Flink版产品使用合集之Flink CDC 2.3.0和Flink 1.17,无法从MySQL数据库中抽取数据,是什么原因导致的
实时计算Flink版作为一种强大的流处理和批处理统一的计算框架,广泛应用于各种需要实时数据处理和分析的场景。实时计算Flink版通常结合SQL接口、DataStream API、以及与上下游数据源和存储系统的丰富连接器,提供了一套全面的解决方案,以应对各种实时计算需求。其低延迟、高吞吐、容错性强的特点,使其成为众多企业和组织实时数据处理首选的技术平台。以下是实时计算Flink版的一些典型使用合集。
19 1
|
2天前
|
关系型数据库 MySQL 数据处理
实时计算 Flink版产品使用合集之如果在 MySQL 表中为某个字段设置了默认值,并且在插入数据时指定了该字段为 NULL,那么 MySQL 是否会使用默认值来填充这个字段
实时计算Flink版作为一种强大的流处理和批处理统一的计算框架,广泛应用于各种需要实时数据处理和分析的场景。实时计算Flink版通常结合SQL接口、DataStream API、以及与上下游数据源和存储系统的丰富连接器,提供了一套全面的解决方案,以应对各种实时计算需求。其低延迟、高吞吐、容错性强的特点,使其成为众多企业和组织实时数据处理首选的技术平台。以下是实时计算Flink版的一些典型使用合集。
13 0
|
4天前
|
关系型数据库 MySQL 数据库
docker MySQL删除数据库时的错误(errno: 39)
docker MySQL删除数据库时的错误(errno: 39)
25 0
|
4天前
|
Java 关系型数据库 MySQL
【MySQL × SpringBoot 突发奇想】全面实现流程 · xlsx文件,Excel表格导入数据库的接口(下)
【MySQL × SpringBoot 突发奇想】全面实现流程 · xlsx文件,Excel表格导入数据库的接口
13 0
|
4天前
|
Java 关系型数据库 MySQL
【MySQL × SpringBoot 突发奇想】全面实现流程 · xlsx文件,Excel表格导入数据库的接口(上)
【MySQL × SpringBoot 突发奇想】全面实现流程 · xlsx文件,Excel表格导入数据库的接口
20 0
|
4天前
|
前端开发 关系型数据库 MySQL
【MySQL × SpringBoot 突发奇想】全面实现流程 · 数据库导出Excel表格文件的接口
【MySQL × SpringBoot 突发奇想】全面实现流程 · 数据库导出Excel表格文件的接口
26 0
http://www.vxiaotou.com