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

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
云数据库 RDS PostgreSQL,高可用系列 2核4GB
简介: 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)

 

相关实践学习
每个IT人都想学的“Web应用上云经典架构”实战
本实验从Web应用上云这个最基本的、最普遍的需求出发,帮助IT从业者们通过“阿里云Web应用上云解决方案”,了解一个企业级Web应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
MySQL数据库入门学习
本课程通过最流行的开源数据库MySQL带你了解数据库的世界。   相关的阿里云产品:云数据库RDS MySQL 版 阿里云关系型数据库RDS(Relational Database Service)是一种稳定可靠、可弹性伸缩的在线数据库服务,提供容灾、备份、恢复、迁移等方面的全套解决方案,彻底解决数据库运维的烦恼。 了解产品详情: https://www.aliyun.com/product/rds/mysql 
相关文章
|
6月前
|
负载均衡 算法 关系型数据库
大数据大厂之MySQL数据库课程设计:揭秘MySQL集群架构负载均衡核心算法:从理论到Java代码实战,让你的数据库性能飙升!
本文聚焦 MySQL 集群架构中的负载均衡算法,阐述其重要性。详细介绍轮询、加权轮询、最少连接、加权最少连接、随机、源地址哈希等常用算法,分析各自优缺点及适用场景。并提供 Java 语言代码实现示例,助力直观理解。文章结构清晰,语言通俗易懂,对理解和应用负载均衡算法具有实用价值和参考价值。
大数据大厂之MySQL数据库课程设计:揭秘MySQL集群架构负载均衡核心算法:从理论到Java代码实战,让你的数据库性能飙升!
|
1月前
|
NoSQL 算法 Redis
【Docker】(3)学习Docker中 镜像与容器数据卷、映射关系!手把手带你安装 MySql主从同步 和 Redis三主三从集群!并且进行主从切换与扩容操作,还有分析 哈希分区 等知识点!
Union文件系统(UnionFS)是一种**分层、轻量级并且高性能的文件系统**,它支持对文件系统的修改作为一次提交来一层层的叠加,同时可以将不同目录挂载到同一个虚拟文件系统下(unite several directories into a single virtual filesystem) Union 文件系统是 Docker 镜像的基础。 镜像可以通过分层来进行继承,基于基础镜像(没有父镜像),可以制作各种具体的应用镜像。
345 5
|
6月前
|
存储 关系型数据库 MySQL
【赵渝强老师】OceanBase数据库从零开始:MySQL模式
《OceanBase数据库从零开始:MySQL模式》是一门包含11章的课程,涵盖OceanBase分布式数据库的核心内容。从体系架构、安装部署到租户管理、用户安全,再到数据库对象操作、事务与锁机制,以及应用程序开发、备份恢复、数据迁移等方面进行详细讲解。此外,还涉及连接路由管理和监控诊断等高级主题,帮助学员全面掌握OceanBase数据库的使用与管理。
353 5
|
7月前
|
负载均衡 算法 关系型数据库
大数据新视界--大数据大厂之MySQL数据库课程设计:MySQL集群架构负载均衡故障排除与解决方案
本文深入探讨 MySQL 集群架构负载均衡的常见故障及排除方法。涵盖请求分配不均、节点无法响应、负载均衡器故障等现象,介绍多种负载均衡算法及故障排除步骤,包括检查负载均衡器状态、调整算法、诊断修复节点故障等。还阐述了预防措施与确保系统稳定性的方法,如定期监控维护、备份恢复策略、团队协作与知识管理等。为确保 MySQL 数据库系统高可用性提供全面指导。
|
分布式计算 关系型数据库 MySQL
大数据-88 Spark 集群 案例学习 Spark Scala 案例 SuperWordCount 计算结果数据写入MySQL
大数据-88 Spark 集群 案例学习 Spark Scala 案例 SuperWordCount 计算结果数据写入MySQL
147 3
|
8月前
|
Ubuntu 关系型数据库 MySQL
容器技术实践:在Ubuntu上使用Docker安装MySQL的步骤。
通过以上的操作,你已经步入了Docker和MySQL的世界,享受了容器技术给你带来的便利。这个旅程中你可能会遇到各种挑战,但是只要你沿着我们划定的路线行进,你就一定可以达到目的地。这就是Ubuntu、Docker和MySQL的灵魂所在,它们为你开辟了一条通往新探索的道路,带你亲身感受到了技术的力量。欢迎在Ubuntu的广阔大海中探索,用Docker技术引领你的航行,随时准备感受新技术带来的震撼和乐趣。
365 16
|
消息中间件 分布式计算 关系型数据库
大数据-140 - ClickHouse 集群 表引擎详解5 - MergeTree CollapsingMergeTree 与其他数据源 HDFS MySQL
大数据-140 - ClickHouse 集群 表引擎详解5 - MergeTree CollapsingMergeTree 与其他数据源 HDFS MySQL
252 0
|
9月前
|
监控 关系型数据库 MySQL
云数据库:从零到一,构建高可用MySQL集群
在互联网时代,数据成为企业核心资产,传统单机数据库难以满足高并发、高可用需求。云数据库通过弹性扩展、分布式架构等优势解决了这些问题,但也面临数据安全和性能优化挑战。本文介绍了如何从零开始构建高可用MySQL集群,涵盖选择云服务提供商、创建实例、配置高可用架构、数据备份恢复及性能优化等内容,并通过电商平台案例展示了具体应用。
|
11月前
|
SQL 关系型数据库 MySQL
PHP与MySQL的高效交互:从基础到实践####
本文深入探讨了PHP与MySQL数据库之间的高效交互技术,涵盖了从基础连接到高级查询优化的全过程。不同于传统的摘要概述,这里我们直接以一段精简代码示例作为引子,展示如何在PHP中实现与MySQL的快速连接与简单查询,随后文章将围绕这一核心,逐步展开详细讲解,旨在为读者提供一个从入门到精通的实战指南。 ```php <?php // 数据库配置信息 $servername = "localhost"; $username = "root"; $password = "password"; $dbname = "test_db"; // 创建连接 $conn = new mysqli($se
311 31
|
11月前
|
缓存 关系型数据库 MySQL
MySQL 索引优化与慢查询优化:原理与实践
通过本文的介绍,希望您能够深入理解MySQL索引优化与慢查询优化的原理和实践方法,并在实际项目中灵活运用这些技术,提升数据库的整体性能。
610 5

热门文章

最新文章

推荐镜像

更多