当前位置:   article > 正文

【项目实战经验】DataKit迁移MySQL到openGauss(下)

【项目实战经验】DataKit迁移MySQL到openGauss(下)

上一篇我们分享了安装、设置、链接、启动等步骤,本篇我们将继续分享迁移、启动~

 

目录

 9. 离线迁移

9.1. 迁移插件安装

中断安装,比如 kill 掉java进程(安装失败也要等待300s)

下载安装包准备上传

缺少mysqlclient lib包

mysql如果是二进制安装的话,我这个版本是没有18这个lib包的

安装成功后的截图

 主机上有对应的进程

10. 全量迁移

10.1. 选中主机,启动迁移

 10.2. 迁移中

 10.3. 迁移结束

 10.4. 日志所在目录

11. 增量迁移

11.1. PG里面创建第二个库

 11.2. 创建在线迁移任务

 11.3. 启动

11.4. 在mysql端进行DDL和DML

mysql 端进行了5个事务

第6次增量

停止增量

 12. 反向迁移

 12.1. 在PG端进行增删改

12.2. PG端DDL 


 9. 离线迁移

 

 

 

 

 

9.1. 迁移插件安装

中断安装,比如 kill 掉java进程(安装失败也要等待300s)
update tb_migration_host_portal_install set install_status=10;

下载安装包准备上传

 

缺少mysqlclient lib包
  • mysql如果是二进制安装的话,我这个版本是没有18这个lib包的
  1. [root@mysqldb lib]# ls -ltrh /usr/local/mysql/lib
  2. total 1001M
  3. -rw-r--r-- 1 mysql mysql 392M Jun 21 2023 libmysqld-debug.a
  4. -rw-r--r-- 1 mysql mysql 43K Jun 21 2023 libmysqlservices.a
  5. -rwxr-xr-x 1 mysql mysql 11M Jun 21 2023 libmysqlclient.so.20.3.30
  6. -rw-r--r-- 1 mysql mysql 26M Jun 21 2023 libmysqlclient.a
  7. -rw-r--r-- 1 mysql mysql 574M Jun 21 2023 libmysqld.a
  8. lrwxrwxrwx 1 mysql mysql 25 Jun 21 2023 libmysqlclient.so.20 -> libmysqlclient.so.20.3.30
  9. lrwxrwxrwx 1 mysql mysql 20 Jun 21 2023 libmysqlclient.so -> libmysqlclient.so.20
  10. drwxr-xr-x 2 mysql mysql 28 Jan 10 13:36 pkgconfig
  11. drwxr-xr-x 4 mysql mysql 28 Jan 10 13:36 mecab
  12. drwxr-xr-x 3 mysql mysql 4.0K Jan 10 13:36 plugin
  13. lrwxrwxrwx 1 root root 25 Jan 10 14:41 libmysqlclient.so.18 -> libmysqlclient.so.20.3.30
  • 在porta安装日志下面,会有如下报错

  1. [root@mysqldb logs]# cat /ops/portal/error.log
  2. /ops/portal/tools/chameleon/chameleon-5.1.0
  3. install.sh: /ops/portal/tools/chameleon/chameleon-5.1.0/venv/bin/chameleon: /venv/bin/python3.6: bad interpreter: No such file or directory
  4. Traceback (most recent call last):
  5. File "/ops/portal/tools/chameleon/chameleon-5.1.0/venv/lib/python3.6/site-packages/MySQLdb/__init__.py", line 18, in <module>
  6. from . import _mysql
  7. ImportError: libmysqlclient.so.18: cannot open shared object file: No such file or directory
  8. During handling of the above exception, another exception occurred:
  • 查看到符合当前mysql的版本,通过yum安装即可

  1. Installed:
  2. mysql-community-libs-compat.x86_64 0:5.7.44-1.el7
  3. Complete!
  4. [root@datakit bin]# rpm -ql mysql-community-libs-compat-5.7.44-1.el7.x86_64
  5. /etc/ld.so.conf.d/mysql-x86_64.conf
  6. /usr/lib64/mysql
  7. /usr/lib64/mysql/libmysqlclient.so.18
  8. /usr/lib64/mysql/libmysqlclient.so.18.1.0
  9. /usr/lib64/mysql/libmysqlclient_r.so.18
  10. /usr/lib64/mysql/libmysqlclient_r.so.18.1.0
  11. /usr/share/doc/mysql-community-libs-compat-5.7.44
  12. /usr/share/doc/mysql-community-libs-compat-5.7.44/LICENSE
  13. /usr/share/doc/mysql-community-libs-compat-5.7.44/README
  • 其他有用命令

  1. # 重新加载lib库
  2. /sbin/ldconfig -v
  3. # 查看位置
  4. locate libmysql
  5. # 手动配置lib库
  6. vi /etc/ld.so.conf.d/mysql.conf
  7. # 查看是否有对应的lib库
  8. ldconfig -p|grep mysql
  • ldconfig,此时安装迁移插件应该没有问题

  1. [root@mysqldb lib]# ldconfig -p|grep mysql
  2. libmysqlclient.so.20 (libc6,x86-64) => /usr/local/mysql/lib/libmysqlclient.so.20
  3. libmysqlclient.so.20 (libc6,x86-64) => /usr/lib64/mysql/libmysqlclient.so.20
  4. libmysqlclient.so.18 (libc6,x86-64) => /usr/lib64/mysql/libmysqlclient.so.18
  5. libmysqlclient.so (libc6,x86-64) => /usr/local/mysql/lib/libmysqlclient.so
  • 如果是在线安装,会遇到403错误,现在要登陆了才能下载

  1. download portal package failed:
  2. --2024-01-09 12:11:24-- https://opengauss.obs.cn-south-1.myhuaweicloud.com/latest/tools/PortalControl-5.1.0.tar.gz
  3. Resolving opengauss.obs.cn-south-1.myhuaweicloud.com (opengauss.obs.cn-south-1.myhuaweicloud.com)... 122.9.127.163, 122.9.127.162
  4. Connecting to opengauss.obs.cn-south-1.myhuaweicloud.com (opengauss.obs.cn-south-1.myhuaweicloud.com)|122.9.127.163|:443... connected.
  5. HTTP request sent, awaiting response... 403 Forbidden
  6. 2024-01-09 12:11:25 ERROR 403: Forbidden.
  • 出现如下提示最终还是能成功安装的:

  1. /ops/portal/tools/chameleon/chameleon-5.1.0
  2. install.sh: /ops/portal/tools/chameleon/chameleon-5.1.0
  3. /venv/bin/chameleon: /venv/bin/python3.6: bad interpreter: No such file or directory
安装成功后的截图

 

 主机上有对应的进程
  1. [root@mysqldb alternatives]# jps
  2. 19073 QuorumPeerMain
  3. 19122 SupportedKafka
  4. 4874 Jps
  5. 19487 SchemaRegistryMai

10. 全量迁移

10.1. 选中主机,启动迁移

 10.2. 迁移中

 10.3. 迁移结束

 

 

 10.4. 日志所在目录

  1. [root@mysqldb datacheck]# pwd
  2. /ops/portal/workspace/2/logs/datacheck
  3. [root@mysqldb datacheck]# ls -ltrh
  4. total 36K
  5. -rw-rw-r-- 1 appadm appadm 2.2K Jan 10 15:31 business-source.log
  6. -rw-rw-r-- 1 appadm appadm 2.1K Jan 10 15:31 business-sink.log
  7. -rw-rw-r-- 1 appadm appadm 282 Jan 10 15:31 business-check.log
  8. -rw-rw-r-- 1 appadm appadm 3.1K Jan 10 15:31 source.log
  9. -rw-rw-r-- 1 appadm appadm 3.3K Jan 10 15:31 sink.log
  10. -rw-rw-r-- 1 appadm appadm 422 Jan 10 15:31 kafka-sink.log
  11. -rw-rw-r-- 1 appadm appadm 422 Jan 10 15:31 kafka-source.log
  12. -rw-rw-r-- 1 appadm appadm 3.3K Jan 10 15:31 check.log
  13. -rw-rw-r-- 1 appadm appadm 2.1K Jan 10 15:31 kafka-check.log
  14. [root@mysqldb datacheck]# ls -l /ops/portal/workspace/2/logs/
  15. total 24
  16. drwxrwxr-x 2 appadm appadm 204 Jan 10 15:30 datacheck
  17. drwxrwxr-x 2 appadm appadm 51 Jan 10 15:30 debezium
  18. -rw-rw-r-- 1 appadm appadm 162 Jan 10 15:31 error.log
  19. -rw-rw-r-- 1 appadm appadm 17400 Jan 10 15:31 full_migration.log
  20. [root@mysqldb datacheck]# find /ops -name schema-registry.log
  21. /ops/portal/workspace/2/logs/debezium/schema-registry.log
  22. /ops/portal/tools/debezium/confluent-5.5.1/logs/schema-registry.log

11. 增量迁移

11.1. PG里面创建第二个库

create database world2 with dbcompatibility='b';

 11.2. 创建在线迁移任务

 11.3. 启动

 

  • 全量迁移完成并校验成功后进入增量迁移

 

 

11.4. 在mysql端进行DDL和DML

mysql 端进行了5个事务
  1. root@localhost 16:08:00 [world]> create table t1(id int primary key,name varchar(32));
  2. Query OK, 0 rows affected (0.01 sec)
  3. root@localhost 16:08:31 [world]> insert into t1 values(1,'zhangsan');
  4. Query OK, 1 row affected (0.01 sec)
  5. root@localhost 16:08:45 [world]> insert into t1 values(2,'22'),(3,'33');
  6. Query OK, 2 rows affected (0.01 sec)
  7. Records: 2 Duplicates: 0 Warnings: 0
  8. root@localhost 16:09:00 [world]> create table city_copy like city;
  9. Query OK, 0 rows affected (0.03 sec)
  10. root@localhost 16:09:22 [world]> insert into city_copy select * from city;
  11. Query OK, 4079 rows affected (0.06 sec)
  12. Records: 4079 Duplicates: 0 Warnings: 0

 上面一直卡住,再起一个的时候报错(内存不足):

OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x0000000680000000,

中间还有一次翻车了

  1. py_opengauss.exceptions.ClientCannotConnectError: could not establish connection to server
  2. CODE: 08001
  3. LOCATION: CLIENT
  4. CONNECTION: [failed]
  5. failures[0]:
  6. socket('192.168.2.3', 5432)
  7. py_opengauss.exceptions.InsufficientPrivilegeError: Please use the original role to connect B-compatibility database first, to load extension dolphin
  8. CODE: 42501
  9. LOCATION: SERVER
  10. CONNECTOR: [IP4] pq://datakit:***@192.168.2.3:5432/world4?[sslmode]=disable
  11. category: None
  12. DRIVER: py_opengauss.driver.pq3.Driver
第6次增量

在mysql端进行增删改和DDL

  1. root@localhost 16:48:04 [world]> delete from t1 where id=3;
  2. Query OK, 1 row affected (0.01 sec)
  3. root@localhost 16:48:12 [world]> insert into t1 values(4,44);
  4. Query OK, 1 row affected (0.01 sec)
  5. root@localhost 16:48:24 [world]> update t1 set name=222 where id=2;
  6. Query OK, 1 row affected (0.00 sec)
  7. Rows matched: 1 Changed: 1 Warnings: 0
  8. root@localhost 16:48:36 [world]> update t1 set name=2223 where id=2;
  9. Query OK, 1 row affected (0.00 sec)
  10. Rows matched: 1 Changed: 1 Warnings: 0
  11. root@localhost 16:49:03 [world]> create table t2 (id int primary key, name char(20));
  12. Query OK, 0 rows affected (0.01 sec)
  13. root@localhost 16:49:41 [world]> insert into t2 select * from t1;
  14. Query OK, 3 rows affected (0.01 sec)
  15. Records: 3 Duplicates: 0 Warnings: 0

 

停止增量

 12. 反向迁移

 

 12.1. 在PG端进行增删改

  1. world4=# \c world4
  2. Non-SSL connection (SSL connection is recommended when requiring high-security)
  3. You are now connected to database "world4" as user "omm".
  4. world4=# set search_path=world;
  5. SET
  6. world4=# select * from t2;
  7. id | name
  8. ----+----------------------
  9. 1 | zhangsan
  10. 2 | 2223
  11. 4 | 44
  12. (3 rows)
  13. world4=# insert into t2 values(5,55);
  14. INSERT 0 1
  15. world4=# update t2 set name=5555 where id=5;
  16. UPDATE 1
  17. world4=# delete from t2 where id=1;
  18. DELETE 1

 

12.2. PG端DDL 

PG建表无法同步到mysql,但是继续在PG继续进行DML,原有表的数据依然能同步到mysql

  1. orld4=# create table pg_table( id bigint primary key);
  2. NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "pg_table_pkey" for table "pg_table"
  3. CREATE TABLE
  4. world4=# create table t3(id bigint primary key);
  5. NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "t3_pkey" for table "t3"
  6. CREATE TABLE
  7. world4=# show tables;
  8. Tables_in_world
  9. -----------------
  10. city
  11. city_copy
  12. country
  13. countrylanguage
  14. pg_table
  15. t1
  16. t2
  17. t3
  18. (8 rows)
  19. world4=# update t2 set name=55555555 where id=5;
  20. UPDATE 1
  21. world4=# create table t4(id bigint);
  22. CREATE TABLE
  23. world4=# insert into t4 values(1),(2);
  24. INSERT 0 2
  25. world4=# select * from t4;
  26. id
  27. ----
  28. 1
  29. 2
  30. (2 rows)

 

 

  1. root@localhost 17:01:41 [world]> show tables;
  2. +-----------------+
  3. | Tables_in_world |
  4. +-----------------+
  5. | city |
  6. | city_copy |
  7. | country |
  8. | countrylanguage |
  9. | t1 |
  10. | t2 |
  11. +-----------------+
  12. 6 rows in set (0.00 sec)
  13. root@localhost 17:03:08 [world]> select * from t2;
  14. +----+----------+
  15. | id | name |
  16. +----+----------+
  17. | 2 | 2223 |
  18. | 4 | 44 |
  19. | 5 | 55555555 |
  20. +----+----------+
  21. 3 rows in set (0.00 sec)

至此,迁移部分实践分享结束,欢迎大家一起交流学习。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/419296
推荐阅读
相关标签
  

闽ICP备14008679号