浅谈OceanBase旁路导入

数据库相关信息

OceanBase 版本:社区版4.2.1.10

OBProxy 版本:4.3.3.0

OB导数工具版本:4.3.1

租户信息:MySQL租户

租户资源:4C10G

旁路导入方式

LOAD DATA 旁路导入

设置系统变量 secure_file_priv

通过本地 Socket 连接数据库设置 secure_file_priv 路径

复制代码
[root@server061 ~]# mysql -S /home/admin/oceanbase/run/sql.sock -uroot@obmysql -paaAA11__
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3221694018
Server version: 5.7.25 OceanBase 4.2.1.10 (r110020012024120420-760d3c19482ba306e5a10e214a8ec64422bbf1f0) (Built Dec  4 2024 20:33:18)

Copyright (c) 2000, 2024, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
mysql>
mysql> SET GLOBAL secure_file_priv = "/home/load";
Query OK, 0 rows affected (0.15 sec)

mysql>
mysql>
配置 secure_file_priv 路径 权限
复制代码
[root@server061 ~]# cd /home/
[root@server061 home]# ll
total 190000
drwxr-xr-x. 7 admin admin       156 Jan  6 11:18 admin
drwxr-xr-x. 5 root  root         42 Dec 26 10:12 data
drwx------  7 gbase gbase      4096 Jan 22 14:23 gbase
drwxr-xr-x  7 10143 10143       245 Dec 11  2019 jdk1.8.0_241
-rw-r--r--  1 root  root  194545143 Jan 23 00:45 jdk-8u241-linux-x64.tar.gz
drwxr-xr-x  2 root  root          6 Jan 25 23:42 load
drwxr-xr-x  3 root  root         86 Jan 23 00:44 loader
drwxr-xr-x  2 root  root       4096 Jan  8 16:36 mysql
drwxr-xr-x  2 root  root       4096 Jan  8 17:15 mysql8
[root@server061 home]#
[root@server061 home]# chown -R admin.admin load
[root@server061 home]#
[root@server061 home]#
导出csv格式文件

重新登录数据库,将 test_order 表数据导出为csv文件

复制代码
[root@server061 home]# mysql -S /home/admin/oceanbase/run/sql.sock -uroot@obmysql -paaAA11__
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3221694648
Server version: 5.7.25 OceanBase 4.2.1.10 (r110020012024120420-760d3c19482ba306e5a10e214a8ec64422bbf1f0) (Built Dec  4 2024 20:33:18)

Copyright (c) 2000, 2024, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use tpccdb;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql>
mysql>
mysql> SELECT * FROM test_order  INTO OUTFILE "/home/load/test.csv" FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n';
Query OK, 15001931 rows affected (41.32 sec)

mysql>
LOAD DATA 命令导入

旁路导入相关参数如下,LOAD DATA 详细语法请参见官网说明

LOAD DATA-V4.2.1-OceanBase 数据库文档-分布式数据库使用文档

重新登录数据库,创建测试表test_load, 使用LOAD DATA 旁路导入命令 将/home/load/test.csv文件数据导入至该表

复制代码
[root@server061 home]# mysql -S /home/admin/oceanbase/run/sql.sock -uroot@obmysql -paaAA11__
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3221695612
Server version: 5.7.25 OceanBase 4.2.1.10 (r110020012024120420-760d3c19482ba306e5a10e214a8ec64422bbf1f0) (Built Dec  4 2024 20:33:18)

Copyright (c) 2000, 2024, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
mysql>
mysql> use tpccdb;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql>
mysql>
mysql> create table test_load  like test_order;
Query OK, 0 rows affected (0.37 sec)

mysql>
mysql>
mysql> LOAD DATA /*+ direct(true,1024) parallel(16) */INFILE '/home/load/test.csv' INTO TABLE test_load FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n';
Query OK, 15001931 rows affected (1 min 3.00 sec)
Records: 15001931  Deleted: 0  Skipped: 0  Warnings: 0

mysql>

OB导数工具 旁路导入

前提条件
导出数据

使用obdump将 test_order 数据导出

复制代码
[root@server65 bin]# ./obdumper -h 10.0.0.61 -P 2883 -uroot@obmysql#obdemo61 -paaAA11__ --sys-user root --sys-password aaAA11__ -D tpccdb --csv --table test_order -f /home/load
导入数据

清空源表数据

复制代码
mysql> truncate table test_order;
Query OK, 0 rows affected (0.07 sec)

mysql>

使用obloader工具将之前导出的CSV文件旁路导入至源表

旁路导入具体参数说明参见官网

旁路导入-V4.3.2.1-OceanBase 导数工具文档-分布式数据库使用文档

复制代码
[root@server65 bin]# ./obloader -h 10.0.0.61 -P 2883 -uroot@obmysql#obdemo61 -paaAA11__ --sys-user root --sys-password aaAA11__ -D tpccdb --csv --table test_load -f /home/load --thread 16 --rpc-port=2885 --direct --parallel=16

旁路导入成功

相关推荐
Leo.yuan2 分钟前
不同数据仓库模型有什么不同?企业如何选择适合的数据仓库模型?
大数据·数据库·数据仓库·信息可视化·spark
麦兜*19 分钟前
MongoDB 6.0 新特性解读:时间序列集合与加密查询
数据库·spring boot·mongodb·spring·spring cloud·系统架构
chat2tomorrow22 分钟前
数据采集平台的起源与演进:从ETL到数据复制
大数据·数据库·数据仓库·mysql·低代码·postgresql·etl
稻草人想看远方24 分钟前
关系型数据库和非关系型数据库
数据库
考虑考虑25 分钟前
Postgerssql格式化时间
数据库·后端·postgresql
千里码aicood34 分钟前
【springboot+vue】党员党建活动管理平台(源码+文档+调试+基础修改+答疑)
java·数据库·spring boot
TDengine (老段)1 小时前
TDengine 选择函数 Max() 用户手册
大数据·数据库·物联网·时序数据库·tdengine·涛思数据
驾驭人生1 小时前
Asp .Net Core 系列:Asp .Net Core 集成 Hangfire+MySQL
数据库·mysql·.netcore
乐迪信息1 小时前
乐迪信息:AI摄像机在智慧煤矿人员安全与行为识别中的技术应用
大数据·人工智能·算法·安全·视觉检测
xhbh6661 小时前
不止是DELETE:MySQL多表关联删除的JOIN语法实战详解
数据库·mysql·程序员·mysql删除语句