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

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介: 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
相关文章
|
16天前
|
缓存 NoSQL 关系型数据库
13- Redis和Mysql如何保证数据⼀致?
该内容讨论了保证Redis和MySQL数据一致性的几种策略。首先提到的两种方法存在不一致风险:先更新MySQL再更新Redis,或先删Redis再更新MySQL。第三种方案是通过MQ异步同步以达到最终一致性,适用于一致性要求较高的场景。项目中根据不同业务需求选择不同方案,如对一致性要求不高的情况不做处理,时效性数据设置过期时间,高一致性需求则使用MQ确保同步,最严格的情况可能涉及分布式事务(如Seata的TCC模式)。
44 6
|
23天前
|
SQL 关系型数据库 MySQL
轻松入门MySQL:保障数据完整性,MySQL事务在进销存管理系统中的应用(12)
轻松入门MySQL:保障数据完整性,MySQL事务在进销存管理系统中的应用(12)
|
2天前
|
SQL 关系型数据库 MySQL
Spring_jdbc数据连接池(mysql实现增、删、改、查)
Spring_jdbc数据连接池(mysql实现增、删、改、查)
8 0
|
4天前
|
存储 数据可视化 关系型数据库
MySQL字段的时间类型该如何选择?千万数据下性能提升10%~30%🚀
本文探讨MySQL中时间类型的选择,阐述datetime、timestamp、整形时间戳等类型特点以及它们在千万级数据量下的查询性能
MySQL字段的时间类型该如何选择?千万数据下性能提升10%~30%🚀
|
29天前
|
关系型数据库 MySQL
MySQL查询当天昨天明天本月上月今年等数据
MySQL查询当天昨天明天本月上月今年等数据
19 2
|
4天前
|
SQL 存储 关系型数据库
MySQL Cluster集群安装及使用
MySQL Cluster集群安装及使用
|
19天前
|
关系型数据库 MySQL 数据库
mysql卸载、下载、安装(window版本)
mysql卸载、下载、安装(window版本)
|
8天前
|
关系型数据库 MySQL 数据库
《MySQL 简易速速上手小册》第1章:MySQL 基础和安装(2024 最新版)
《MySQL 简易速速上手小册》第1章:MySQL 基础和安装(2024 最新版)
33 4
|
1月前
|
Ubuntu 关系型数据库 MySQL
Ubuntu 中apt 安装MySQL数据库
Ubuntu 中apt 安装MySQL数据库
69 0
|
1天前
|
关系型数据库 MySQL 数据安全/隐私保护
安装mysql和远程连接
安装mysql和远程连接
10 0

热门文章

最新文章