oceanbase导出导入数据csv
https://www.oceanbase.com/softwarecenter-enterprise
选择【OceanBase 导数工具】,随便填写信息,然后可下载。
工具下载链接如下:
https://obbusiness-private.oss-cn-shanghai.aliyuncs.com/download-center/opensource/ob_loader_dumper/4.3.3.1/ob-loader-dumper-4.3.3.1-RELEASE.zip
上传到linux主机后解压即可使用。
需确认安装了java1.8以上版本可运行:
[root@ob ~]# java -version
java version "1.8.0_221"
Java(TM) SE Runtime Environment (build 1.8.0_221-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.221-b11, mixed mode)
注意:
csv文件格式必须为"表名.xxx.csv"或"表名.csv"的格式,可自动识别。否则导入失败忽略。
参数--skip-header跳过第一行csv的标题行。如果导入或导出所有,则指定—all参数。
导出csv:
如果指定--all则导出所有表
[root@ob TABLE]# /root/ob-loader-dumper-4.3.3.1-RELEASE/bin/obdumper -h 192.168.207.18 -P 2881 -u gistar -t lnzyob -p xxx#pwd --csv -f /root/csv1/ --skip-check-dir --table 'jyc,dict_sap'
2025-06-13 14:10:05 [INFO] Parsed args:
[--csv] true
[--file-path] /root/csv1/
[--host] 192.168.207.18
[--port] 2881
[--user] gistar
[--tenant] lnzyob
[--password] ******
[--sys-user] root
[--table] [jyc, dict_sap]
[--skip-check-dir] true
2025-06-13 14:10:05 [WARN] The Java version (1.8.0_221) you are currently using is not recommended. Recommended range: [1.8.0_300, 9.0.0)
2025-06-13 14:10:06 [INFO] Log files will be written to /root/csv1/logs
2025-06-13 14:10:06 [INFO] Trying to establish JDBC connection to `gistar@lnzyob`...
2025-06-13 14:10:07 [INFO] Server Mode: OBORACLE-4.2.5.3
2025-06-13 14:10:07 [INFO] Manifest "/root/csv1/.MANIFEST.bin" has been saved
2025-06-13 14:10:07 [INFO] Querying table column metadata, this might take a while...
2025-06-13 14:10:07 [INFO] Filtering out empty tables...
2025-06-13 14:10:07 [INFO] Preloading all primary keys...
2025-06-13 14:10:08 [INFO] Parallel write is set to false.
2025-06-13 14:10:08 [INFO] A total of 2 TABLE need to be dumped.
2025-06-13 14:10:09 [INFO] Query table entry for table "JYC" success. Elapsed: 1.776 s
2025-06-13 14:10:09 [INFO] Query table entry for table "DICT_SAP" success. Elapsed: 1.770 s
2025-06-13 14:10:09 [INFO] Generating sub-tasks for table "DICT_SAP" by partitions and primary/unique keys...
2025-06-13 14:10:09 [INFO] Generating sub-tasks for table "JYC" by partitions and primary/unique keys...
2025-06-13 14:10:09 [INFO] Generate 1 sub-tasks for table "JYC" succeed. Elapsed: 15.18 ms
2025-06-13 14:10:09 [INFO] Generate 1 sub-tasks for table "DICT_SAP" succeed. Elapsed: 28.59 ms
2025-06-13 14:10:09 [INFO] TABLE "JYC" is dumping, and several objects are waiting. Remain: [1/2]
2025-06-13 14:10:09 [INFO] Start up the log reporter task succeed.
2025-06-13 14:10:09 [INFO] TABLE "DICT_SAP" is dumping, and several objects are waiting. Remain: [0/2]
2025-06-13 14:10:09 [INFO] Start 32 record dump threads for 2 dump tasks finished
2025-06-13 14:10:10 [INFO] Dump data to "/root/csv1/data/GISTAR/TABLE/JYC.csv" finished.
2025-06-13 14:10:10 [INFO] Dump data to "/root/csv1/data/GISTAR/TABLE/DICT_SAP.csv" finished.
2025-06-13 14:10:10 [INFO] Merge file '/root/csv1/data/GISTAR/TABLE/JYC.csv' of table 'JYC' finished, total files: 1, remaining: 0. Elapsed: 12.96 ms
2025-06-13 14:10:10 [INFO] Merge file '/root/csv1/data/GISTAR/TABLE/DICT_SAP.csv' of table 'DICT_SAP' finished, total files: 1, remaining: 0. Elapsed: 14.07 ms
2025-06-13 14:10:10 [INFO] ---------- Finished Tasks: 2 Running Tasks: 0 Progress: 100.00% Finished File Merge Tasks: 2 Running File Merge Tasks: 0 ----------
2025-06-13 14:10:10 [INFO]
All Dump Tasks Finished:
----------------------------------------------------------------------------------------------------------------------------
No.# | Type | Name | Count | Status
----------------------------------------------------------------------------------------------------------------------------
1 | TABLE | JYC | 20 | SUCCESS
2 | TABLE | DICT_SAP | 3 | SUCCESS
----------------------------------------------------------------------------------------------------------------------------
Total Count: 23 End Time: 2025-06-13 14:10:10
2025-06-13 14:10:10 [INFO] Dump record finished. Total Elapsed: 2.895 s
2025-06-13 14:10:11 [INFO] System exit 0
[root@ob TABLE]# pwd
/root/csv1/data/GISTAR/TABLE
[root@ob TABLE]# ll
total 12
-rw-r--r--. 1 root root 45 Jun 13 14:10 DICT_SAP.csv
-rw-r--r--. 1 root root 964 Jun 13 14:10 JYC.csv
-rw-r--r--. 1 root root 548 Jun 13 14:01 SYS_CONFIG.csv
[root@ob TABLE]# more DICT_SAP.csv
'ID','NAME'
1,'单端'
2,'甲端'
3,'乙端'
[root@ob TABLE]# more JYC.csv
'ID','NAME','CREATE_TIME','LOGIN_TIME'
'1','aaa','2025-06-13 12:20:33','2025-06-13 12:20:33.111000'
'222','bbb','2025-06-13 13:20:00','2025-06-13 12:30:33.111000'
'33',\N,\N,'2025-06-13 12:30:33.111000'
'555','aaaaaa',\N,\N
'1','aaa','2025-06-13 12:20:33','2025-06-13 12:20:33.111000'
'222','bbb','2025-06-13 13:20:00','2025-06-13 12:30:33.111000'
'33',\N,\N,'2025-06-13 12:30:33.111000'
'555','aaaaaa',\N,\N
'1','aaa','2025-06-13 12:20:33','2025-06-13 12:20:33.111000'
'222','bbb','2025-06-13 13:20:00','2025-06-13 12:30:33.111000'
'33',\N,\N,'2025-06-13 12:30:33.111000'
'555','aaaaaa',\N,\N
'1','aaa','2025-06-13 12:20:33','2025-06-13 12:20:33.111000'
'222','bbb','2025-06-13 13:20:00','2025-06-13 12:30:33.111000'
'33',\N,\N,'2025-06-13 12:30:33.111000'
'555','aaaaaa',\N,\N
'1','aaa','2025-06-13 12:20:33','2025-06-13 12:20:33.111000'
'222','bbb','2025-06-13 13:20:00','2025-06-13 12:30:33.111000'
'33',\N,\N,'2025-06-13 12:30:33.111000'
'555','aaaaaa',\N,\N
[root@ob TABLE]#
导入csv
操作:
[root@ob TABLE]# obclient -h192.168.207.18 -P2881 -ugistar@lnzyob -pxxx#pwd -A
Welcome to the OceanBase. Commands end with ; or \g.
Your OceanBase connection id is 3221551657
Server version: OceanBase 4.2.5.3 (r103000152025033110-f5b88cd987f23383677f2eb53cf76ed38a48979b) (Built Mar 31 2025 11:08:20)
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(GISTAR@lnzyob)[GISTAR]> truncate table jyc;
Query OK, 0 rows affected (0.150 sec)
obclient(GISTAR@lnzyob)[GISTAR]> truncate table DICT_SAP;
Query OK, 0 rows affected (0.139 sec)
obclient(GISTAR@lnzyob)[GISTAR]> exit
Bye
[root@ob TABLE]# /root/ob-loader-dumper-4.3.3.1-RELEASE/bin/obloader -h 192.168.207.18 -P 2881 -u gistar -t lnzyob -p xxx#pwd --csv -f /root/csv1/ --skip-header --table 'jyc,DICT_SAP'
2025-06-13 14:12:22 [INFO] Parsed args:
[--csv] true
[--file-path] /root/csv1/
[--skip-header] true
[--host] 192.168.207.18
[--port] 2881
[--user] gistar
[--tenant] lnzyob
[--password] ******
[--sys-user] root
[--table] [jyc, DICT_SAP]
2025-06-13 14:12:22 [WARN] The Java version (1.8.0_221) you are currently using is not recommended. Recommended range: [1.8.0_300, 9.0.0)
2025-06-13 14:12:23 [INFO] Log files will be written to /root/csv1/logs
2025-06-13 14:12:23 [INFO] Trying to establish JDBC connection to `gistar@lnzyob`...
2025-06-13 14:12:23 [INFO] Server Mode: OBORACLE-4.2.5.3
2025-06-13 14:12:23 [INFO] Manifest has been saved to "/root/csv1/.MANIFEST.bin"
2025-06-13 14:12:23 [INFO] Querying table column metadata, this might take a while...
2025-06-13 14:12:23 [INFO] Listing all matched data files in dest path...
2025-06-13 14:12:23 [INFO] Cannot find a binding for "file:/root/csv1/data/GISTAR/TABLE/SYS_CONFIG.csv", ignore it
2025-06-13 14:12:23 [INFO] Binding table: "JYC" to file: "file:/root/csv1/data/GISTAR/TABLE/JYC.csv" finished
2025-06-13 14:12:23 [INFO] Binding table: "DICT_SAP" to file: "file:/root/csv1/data/GISTAR/TABLE/DICT_SAP.csv" finished
2025-06-13 14:12:23 [INFO] Find 2 data files in: "/root/csv1/" success. Elapsed: 15.45 ms
2025-06-13 14:12:23 [INFO] Splitting data files into 64 MB logical chunks...
2025-06-13 14:12:23 [INFO] Split 2 data files to 2 logical chunks success. Elapsed: 26.41 ms
2025-06-13 14:12:23 [INFO] Bootstrap with Max Heap: 3 GB, Safe Heap: 3.12 GB
2025-06-13 14:12:23 [INFO] Querying primary/unique constraints metadata for data replacing...
2025-06-13 14:12:23 [INFO] Query table entry for table: "DICT_SAP" finished. Remain: 1
2025-06-13 14:12:23 [INFO] Query table entry for table: "JYC" finished. Remain: 0
2025-06-13 14:12:24 [INFO] Query leader location of table: "JYC" finished. Remain: 1
2025-06-13 14:12:24 [INFO] Query leader location of table: "DICT_SAP" finished. Remain: 0
2025-06-13 14:12:24 [INFO] Waiting to calculate leader for 2 subfiles....
2025-06-13 14:12:24 [INFO] Waiting to refresh observer load status....
2025-06-13 14:12:24 [INFO] Create 1024 slots for ring buffer finished. [192.168.207.18:2881]
2025-06-13 14:12:24 [INFO] Start 32 database writer threads finished. [192.168.207.18:2881]
2025-06-13 14:12:24 [INFO] Start 32 record file reader threads success
2025-06-13 14:12:24 [INFO] File: "/root/csv1/data/GISTAR/TABLE/JYC.csv" has been parsed finished
2025-06-13 14:12:24 [INFO] File: "/root/csv1/data/GISTAR/TABLE/DICT_SAP.csv" has been parsed finished
2025-06-13 14:12:25 [INFO] ---------- Finished Tasks: 2 Running Tasks: 0 Progress: 100.00% ----------
2025-06-13 14:12:25 [INFO]
All Load Tasks Finished:
----------------------------------------------------------------------------------------------------------------------------
No.# | Type | Name | Count | Status
----------------------------------------------------------------------------------------------------------------------------
1 | TABLE | JYC | 20 -> 20 | SUCCESS
2 | TABLE | DICT_SAP | 3 -> 3 | SUCCESS
----------------------------------------------------------------------------------------------------------------------------
Total Count: 23 End Time: 2025-06-13 14:12:25
2025-06-13 14:12:25 [INFO] Load record finished. Total Elapsed: 1.691 s
2025-06-13 14:12:25 [INFO] System exit 0
[root@ob TABLE]# obclient -h192.168.207.18 -P2881 -ugistar@lnzyob -pres#pwd -A
Welcome to the OceanBase. Commands end with ; or \g.
Your OceanBase connection id is 3221554871
Server version: OceanBase 4.2.5.3 (r103000152025033110-f5b88cd987f23383677f2eb53cf76ed38a48979b) (Built Mar 31 2025 11:08:20)
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(GISTAR@lnzyob)[GISTAR]> select * from DICT_SAP;
+------+--------+
| ID | NAME |
+------+--------+
| 1 | 单端 |
| 2 | 甲端 |
| 3 | 乙端 |
+------+--------+
3 rows in set (0.002 sec)
obclient(GISTAR@lnzyob)[GISTAR]> select * from JYC;
+------+--------+-------------+------------------------------+
| ID | NAME | CREATE_TIME | LOGIN_TIME |
+------+--------+-------------+------------------------------+
| 1 | aaa | 13-JUN-25 | 13-JUN-25 12.20.33.111000 PM |
| 222 | bbb | 13-JUN-25 | 13-JUN-25 12.30.33.111000 PM |
| 33 | NULL | NULL | 13-JUN-25 12.30.33.111000 PM |
| 555 | aaaaaa | NULL | NULL |
| 1 | aaa | 13-JUN-25 | 13-JUN-25 12.20.33.111000 PM |
| 222 | bbb | 13-JUN-25 | 13-JUN-25 12.30.33.111000 PM |
| 33 | NULL | NULL | 13-JUN-25 12.30.33.111000 PM |
| 555 | aaaaaa | NULL | NULL |
| 1 | aaa | 13-JUN-25 | 13-JUN-25 12.20.33.111000 PM |
| 222 | bbb | 13-JUN-25 | 13-JUN-25 12.30.33.111000 PM |
| 33 | NULL | NULL | 13-JUN-25 12.30.33.111000 PM |
| 555 | aaaaaa | NULL | NULL |
| 1 | aaa | 13-JUN-25 | 13-JUN-25 12.20.33.111000 PM |
| 222 | bbb | 13-JUN-25 | 13-JUN-25 12.30.33.111000 PM |
| 33 | NULL | NULL | 13-JUN-25 12.30.33.111000 PM |
| 555 | aaaaaa | NULL | NULL |
| 1 | aaa | 13-JUN-25 | 13-JUN-25 12.20.33.111000 PM |
| 222 | bbb | 13-JUN-25 | 13-JUN-25 12.30.33.111000 PM |
| 33 | NULL | NULL | 13-JUN-25 12.30.33.111000 PM |
| 555 | aaaaaa | NULL | NULL |
+------+--------+-------------+------------------------------+
20 rows in set (0.003 sec)
obclient(GISTAR@lnzyob)[GISTAR]>
参考:
https://www.oceanbase.com/docs/common-oceanbase-dumper-loader-1000000002781912
https://www.oceanbase.com/docs/common-oceanbase-dumper-loader-1000000001583710
https://www.oceanbase.com/docs/common-oceanbase-database-cn-1000000002017398
https://www.oceanbase.com/docs/common-oceanbase-dumper-loader-1000000001583694