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

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 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)

 

相关实践学习
如何快速连接云数据库RDS MySQL
本场景介绍如何通过阿里云数据管理服务DMS快速连接云数据库RDS MySQL,然后进行数据表的CRUD操作。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
5天前
|
关系型数据库 MySQL Linux
在Linux环境下备份Docker中的MySQL数据并传输到其他服务器以实现数据级别的容灾
以上就是在Linux环境下备份Docker中的MySQL数据并传输到其他服务器以实现数据级别的容灾的步骤。这个过程就像是一场接力赛,数据从MySQL数据库中接力棒一样传递到备份文件,再从备份文件传递到其他服务器,最后再传递回MySQL数据库。这样,即使在灾难发生时,我们也可以快速恢复数据,保证业务的正常运行。
63 28
|
22天前
|
Ubuntu 关系型数据库 MySQL
容器技术实践:在Ubuntu上使用Docker安装MySQL的步骤。
通过以上的操作,你已经步入了Docker和MySQL的世界,享受了容器技术给你带来的便利。这个旅程中你可能会遇到各种挑战,但是只要你沿着我们划定的路线行进,你就一定可以达到目的地。这就是Ubuntu、Docker和MySQL的灵魂所在,它们为你开辟了一条通往新探索的道路,带你亲身感受到了技术的力量。欢迎在Ubuntu的广阔大海中探索,用Docker技术引领你的航行,随时准备感受新技术带来的震撼和乐趣。
74 16
|
1月前
|
存储 SQL 关系型数据库
【YashanDB知识库】MySQL迁移至崖山char类型数据自动补空格问题
**简介**:在MySQL迁移到崖山环境时,若字段类型为char(2),而应用存储的数据仅为'0'或'1',查询时崖山会自动补空格。原因是mysql的sql_mode可能启用了PAD_CHAR_TO_FULL_LENGTH模式,导致保留CHAR类型尾随空格。解决方法是与应用确认数据需求,可将崖山环境中的char类型改为varchar类型以规避补空格问题,适用于所有版本。
|
25天前
|
SQL 关系型数据库 MySQL
【YashanDB知识库】字符集latin1的MySQL中文数据如何迁移到YashanDB
本文探讨了在使用YMP 23.2.1.3迁移MySQL Server字符集为latin1的中文数据至YashanDB时出现乱码的问题。问题根源在于MySQL latin1字符集存放的是实际utf8编码的数据,而YMP尚未支持此类场景。文章提供了两种解决方法:一是通过DBeaver直接迁移表数据;二是将MySQL表数据转换为Insert语句后手动插入YashanDB。同时指出,这两种方法适合单张表迁移,多表迁移可能存在兼容性问题,建议对问题表单独处理。
【YashanDB知识库】字符集latin1的MySQL中文数据如何迁移到YashanDB
|
30天前
|
缓存 NoSQL 关系型数据库
Redis和Mysql如何保证数据⼀致?
1. 先更新Mysql,再更新Redis,如果更新Redis失败,可能仍然不⼀致 2. 先删除Redis缓存数据,再更新Mysql,再次查询的时候在将数据添加到缓存中 这种⽅案能解决1 ⽅案的问题,但是在⾼并发下性能较低,⽽且仍然会出现数据不⼀致的问题,⽐如线程1删除了 Redis缓存数据,正在更新Mysql,此时另外⼀个查询再查询,那么就会把Mysql中⽼数据⼜查到 Redis中 1. 使用MQ异步同步, 保证数据的最终一致性 我们项目中会根据业务情况 , 使用不同的方案来解决Redis和Mysql的一致性问题 : 1. 对于一些一致性要求不高的场景 , 不做处理例如 : 用户行为数据 ,
|
2月前
|
Java 关系型数据库 MySQL
SpringBoot 通过集成 Flink CDC 来实时追踪 MySql 数据变动
通过详细的步骤和示例代码,您可以在 SpringBoot 项目中成功集成 Flink CDC,并实时追踪 MySQL 数据库的变动。
472 43
|
2月前
|
存储 SQL 关系型数据库
MySQL底层概述—4.InnoDB数据文件
本文介绍了InnoDB表空间文件结构及其组成部分,包括表空间、段、区、页和行。表空间是最高逻辑层,包含多个段;段由若干个区组成,每个区包含64个连续的页,页用于存储多条行记录。文章还详细解析了Page结构,分为通用部分(文件头与文件尾)、数据记录部分和页目录部分。此外,文中探讨了行记录格式,包括四种行格式(Redundant、Compact、Dynamic和Compressed),重点介绍了Compact行记录格式及其溢出机制。最后,文章解释了不同行格式的特点及应用场景,帮助理解InnoDB存储引擎的工作原理。
MySQL底层概述—4.InnoDB数据文件
|
2月前
|
SQL 关系型数据库 MySQL
基于SQL Server / MySQL进行百万条数据过滤优化方案
对百万级别数据进行高效过滤查询,需要综合使用索引、查询优化、表分区、统计信息和视图等技术手段。通过合理的数据库设计和查询优化,可以显著提升查询性能,确保系统的高效稳定运行。
77 9
|
2月前
|
监控 关系型数据库 MySQL
MySQL和SQLSugar百万条数据查询分页优化
在面对百万条数据的查询时,优化MySQL和SQLSugar的分页性能是非常重要的。通过合理使用索引、调整查询语句、使用缓存以及采用高效的分页策略,可以显著提高查询效率。本文介绍的技巧和方法,可以为开发人员在数据处理和查询优化中提供有效的指导,提升系统的性能和用户体验。掌握这些技巧后,您可以在处理海量数据时更加游刃有余。
210 9
|
2月前
|
监控 关系型数据库 MySQL
云数据库:从零到一,构建高可用MySQL集群
在互联网时代,数据成为企业核心资产,传统单机数据库难以满足高并发、高可用需求。云数据库通过弹性扩展、分布式架构等优势解决了这些问题,但也面临数据安全和性能优化挑战。本文介绍了如何从零开始构建高可用MySQL集群,涵盖选择云服务提供商、创建实例、配置高可用架构、数据备份恢复及性能优化等内容,并通过电商平台案例展示了具体应用。