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

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

 

相关实践学习
如何在云端创建MySQL数据库
开始实验后,系统会自动创建一台自建MySQL的 源数据库 ECS 实例和一台 目标数据库 RDS。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
25天前
|
安全 关系型数据库 MySQL
如何将数据从MySQL同步到其他系统
【10月更文挑战第17天】如何将数据从MySQL同步到其他系统
143 0
|
1月前
|
SQL 前端开发 关系型数据库
全表数据核对 ,行数据核对,列数据核对,Mysql 8.0 实例(sample database classicmodels _No.3 )
全表数据核对 ,行数据核对,列数据核对,Mysql 8.0 实例(sample database classicmodels _No.3 )
46 0
全表数据核对 ,行数据核对,列数据核对,Mysql 8.0 实例(sample database classicmodels _No.3 )
|
1月前
|
关系型数据库 MySQL 数据库
mysql 里创建表并插入数据
【10月更文挑战第5天】
117 1
|
1月前
|
分布式计算 关系型数据库 MySQL
大数据-88 Spark 集群 案例学习 Spark Scala 案例 SuperWordCount 计算结果数据写入MySQL
大数据-88 Spark 集群 案例学习 Spark Scala 案例 SuperWordCount 计算结果数据写入MySQL
48 3
|
7天前
|
存储 Oracle 关系型数据库
【赵渝强老师】MySQL InnoDB的数据文件与重做日志文件
本文介绍了MySQL InnoDB存储引擎中的数据文件和重做日志文件。数据文件包括`.ibd`和`ibdata`文件,用于存放InnoDB数据和索引。重做日志文件(redo log)确保数据的可靠性和事务的持久性,其大小和路径可由相关参数配置。文章还提供了视频讲解和示例代码。
113 11
【赵渝强老师】MySQL InnoDB的数据文件与重做日志文件
|
7天前
|
缓存 NoSQL 关系型数据库
Redis和Mysql如何保证数据⼀致?
在项目中,为了解决Redis与Mysql的数据一致性问题,我们采用了多种策略:对于低一致性要求的数据,不做特别处理;时效性数据通过设置缓存过期时间来减少不一致风险;高一致性但时效性要求不高的数据,利用MQ异步同步确保最终一致性;而对一致性和时效性都有高要求的数据,则采用分布式事务(如Seata TCC模式)来保障。
39 14
|
10天前
|
SQL 前端开发 关系型数据库
SpringBoot使用mysql查询昨天、今天、过去一周、过去半年、过去一年数据
SpringBoot使用mysql查询昨天、今天、过去一周、过去半年、过去一年数据
40 9
|
21天前
|
SQL Java 关系型数据库
java连接mysql查询数据(基础版,无框架)
【10月更文挑战第12天】该示例展示了如何使用Java通过JDBC连接MySQL数据库并查询数据。首先在项目中引入`mysql-connector-java`依赖,然后通过`JdbcUtil`类中的`main`方法实现数据库连接、执行SQL查询及结果处理,最后关闭相关资源。
|
18天前
|
SQL 关系型数据库 MySQL
定时任务频繁插入数据导致锁表问题 -> 查询mysql进程
定时任务频繁插入数据导致锁表问题 -> 查询mysql进程
38 1
|
19天前
|
SQL 关系型数据库 MySQL
mysql数据误删后的数据回滚
【11月更文挑战第1天】本文介绍了四种恢复误删数据的方法:1. 使用事务回滚,通过 `pymysql` 库在 Python 中实现;2. 使用备份恢复,通过 `mysqldump` 命令备份和恢复数据;3. 使用二进制日志恢复,通过 `mysqlbinlog` 工具恢复特定位置的事件;4. 使用延迟复制从副本恢复,通过停止和重启从库复制来恢复数据。每种方法都有详细的步骤和示例代码。