OBDUMPER如何只导出数据,不导出结构

不要加–ddl就只导出数据不导出结构了

2 个赞

目前是导入的时候加了–auto-column-mapping参数还是提示Cause: The number of columns parsed does not match the number of columns in the table

1 个赞

你好。发一下完整命令行参数,源文件内容示例和目标表结构?我们复现一下

2 个赞

大哥,注意下隐藏掉密码…

2 个赞

忘了忘了
~/ob-loader-dumper-4.3.2.1-RELEASE/bin/obloader -h 192.168.2.96 -P 2883 -u root@back#slaveob -p -D histroy --csv --table sc_order_ob_test_copy1 --auto-column-mapping -f “/opt/output/” --file-regular-expression ‘.*.csv’
导入的命令是这样的
这个是导出的csv文件的列名
‘id’,‘time’,‘authcode’,‘countprice’,‘createtime’,‘customertype’,‘disable’,‘discount’,‘follow_ticket’,‘follow_ticket_time’,‘iccard’,‘invoice_time’,‘invoice_title’,‘invoice_type’,‘is_comment’,‘is_invoice’,‘isbill’,‘mj_coupon_discount’,‘mj_discount’,‘name’,‘native_orderno’,‘number’,‘openid’,‘order_type’,‘orderno’,‘paymoney’,‘payname’,‘paysource’,‘paystatus’,‘paystatustime’,‘paytime’,‘port’,‘price’,‘remind’,‘sourcetype’,‘spid’,‘sta_coupon_discount’,‘sta_discount’,‘state’,‘taxnumber’,‘third_content’,‘third_orderno’,‘updatetime’,‘cardid’,‘class_shift’,‘gun’,‘mj_promotionid’,‘oligasid’,‘openeruserid’,‘plateid’,‘promotionid’,‘rechargeid’,‘stationid’,‘userid’,‘vcardid’,‘paylabel’,‘platform_price’,‘pay_mer_no’,‘remark’,‘univalent’,‘use_balance’,‘use_givebalance’,‘radio_iccard’,‘finishactivity’,‘handle_give’,‘pay_promotionid’,‘pay_pro_discount’,‘handle_share’,‘appid’,‘can_refund_givemoney’,‘can_refund_integral’,‘can_refund_money’,‘refundmoney’,‘allinpay_orderid’,‘lasttime’,‘accountid’,‘ismessage’,‘orderfeesid’,‘channel’,‘pay_mer_appid’,‘pay_mer_key’,‘refundstatus’,‘fuelcard’,‘account’,‘card’,‘cardnumber’,‘classid’,‘company’,‘companyid’,‘csid’,‘guns’,‘icnumber’,‘integral’,‘iscredit’,‘oil’,‘opener’,‘platenumber’,‘station’,‘user’,‘ictype’,‘fuelid’,‘linkid’,‘goods_orderno’,‘recharge_grouprule’,‘phonei’,‘recharge_stationid’,‘is_sale’
这个是目标表字段
id,authcode,countprice,createtime,customertype,disable,discount,follow_ticket,follow_ticket_time,iccard,invoice_time,invoice_title,invoice_type,is_comment,is_invoice,isbill,mj_coupon_discount,mj_discount,name,native_orderno,number,openid,order_type,orderno,paymoney,payname,paysource,paystatus,paystatustime,paytime,port,price,remind,sourcetype,spid,sta_coupon_discount,sta_discount,state,taxnumber,third_content,third_orderno,updatetime,cardid,class_shift,gun,mj_promotionid,oligasid,openeruserid,plateid,promotionid,rechargeid,stationid,userid,vcardid,paylabel,platform_price,pay_mer_no,remark,univalent,use_balance,use_givebalance,radio_iccard,finishactivity,handle_give,pay_promotionid,pay_pro_discount,handle_share,appid,can_refund_givemoney,can_refund_integral,can_refund_money,refundmoney,allinpay_orderid,lasttime,accountid,ismessage,orderfeesid,channel,pay_mer_appid,pay_mer_key,refundstatus,fuelcard,account,card,cardnumber,classid,company,companyid,csid,guns,icnumber,integral,iscredit,oil,opener,platenumber,station,user,ictype,fuelid,linkid,goods_orderno,recharge_grouprule,phonei,recharge_stationid,is_sale,begintime,start_pressure,end_pressure

1 个赞

sc_order_ob_test_copy1 的表结构提供下,谢谢:pray:

1 个赞

目前可以导大部分数据进去,但还是有部分数据会报这个The number of columns parsed does not match the number of columns in the table,为什么只有一小部分的数据有问题

1 个赞

根据文档库中的信息,对于您提到的问题,可以分点进行解答:

  1. 关于obdumper只导出数据不导出结构

    • 在使用obdumper时,如果只想导出数据而不导出表结构,可以通过指定参数来实现。从您的命令中可以看到,您已经指定了--csv--table参数,这确实会导出表的数据以及一些元数据(如表结构)。为了确保只导出数据,您可以尝试使用--data-only选项(如果版本支持),或者在后续处理CSV文件时忽略掉不需要的结构信息行。
    • 参考官方文档《OceanBase 导数工具》文档 产品介绍,其中提到obdumper支持多种格式导出,但具体到只导出数据的操作,建议查看最新版本的手册确认是否有更直接的方式。
  2. 关于obloader导入时列数不匹配的问题

    • 您提到即使使用了--auto-column-mapping参数仍然遇到“列数解析与表定义不符”的错误。这个问题可能是因为源文件中的某些记录存在额外字段或缺失字段导致的。尽管--auto-column-mapping应该能够根据列名自动映射,但如果源文件中有不符合预期的情况(例如空值、特殊字符等),可能会引起解析失败。
    • 解决方案之一是先检查并清理源CSV文件,确保每一行的列数一致且符合目标表的定义。此外,也可以考虑通过预处理步骤去除不必要的列,或者调整目标表结构以适应所有可能的输入情况。
    • 如果问题依然存在,可以尝试手动指定列映射关系,而不是依赖自动映射。即,在执行obloader命令时明确指出哪些源文件列对应于目标表中的哪些列,这样可以避免因自动匹配失误而引发的问题。
  3. 关于部分数据成功导入而另一部分失败的现象

    • 这种情况通常表明大部分数据格式是正确的,但有少部分记录存在问题。可能是这些特定记录中含有特殊字符、空值或其他异常内容,使得它们无法正确地被解析为预期的列数。
    • 建议对失败的日志进行详细分析,找出具体的错误记录,并针对性地修正这些问题。同时,可以在导入前对整个数据集进行预验证,提前发现潜在的问题记录并加以处理。

综上所述,针对您当前遇到的问题,建议采取以下措施:

  • 确认obdumper是否支持--data-only等类似参数用于仅导出数据;
  • 清理源CSV文件,保证每条记录的列数一致;
  • 尝试手动指定列映射规则,代替自动映射;
  • 对导入失败的日志进行深入分析,定位并修复问题记录。

希望以上建议能帮助您解决问题。如果还有其他疑问,欢迎继续交流。

详情请参考:

  1. 使用导数工具进行数据迁移
  2. 数据导入策略与最佳实践
  3. EXPORT_INDEX_STATS
  4. 并行执行入门实践
  5. 并行执行分类与优化
  6. OceanBase 生态工具介绍
  7. EXPORT_COLUMN_STATS
  8. 使用 OceanBase 导数工具从 OceanBase 集群 Oracle 租户迁移数据到 MySQL 租户
  9. 使用 OceanBase 导数工具在 OceanBase 集群 MySQL 租户间迁移数据
2 个赞

记得在obca coud课程里面说的,obdumper是oceanbase的一个导出工具有详细介绍。

如何手动指定哪些源文件列对应于目标表中的哪些列,在文档里没有找到呢

根据文档库中的信息,虽然直接的手动列映射参数在某些文档中可能没有明确提及,但可以通过以下几种方式实现手动指定源文件列与目标表列的对应关系。以下是详细的步骤和建议:

1. 使用 obloader-c--columns 参数

obloader 支持通过 -c--columns 参数来手动指定列映射。您可以列出源文件中的列名,并将其与目标表中的列名一一对应。

示例命令:

~/ob-loader-dumper-4.3.2.1-RELEASE/bin/obloader \
  -h 192.168.2.96 \
  -P 2883 \
  -u root@back#slaveob \
  -p \
  -D history \
  --csv \
  --table sc_order_ob_test_copy1 \
  -c "id,authcode,countprice,createtime,customertype,disable,discount,follow_ticket,follow_ticket_time,iccard,invoice_time,invoice_title,invoice_type,is_comment,is_invoice,isbill,mj_coupon_discount,mj_discount,name,native_orderno,number,openid,order_type,orderno,paymoney,payname,paysource,paystatus,paystatustime,paytime,port,price,remind,sourcetype,spid,sta_coupon_discount,sta_discount,state,taxnumber,third_content,third_orderno,updatetime,cardid,class_shift,gun,mj_promotionid,oligasid,openeruserid,plateid,promotionid,rechargeid,stationid,userid,vcardid,paylabel,platform_price,pay_mer_no,remark,univalent,use_balance,use_givebalance,radio_iccard,finishactivity,handle_give,pay_promotionid,pay_pro_discount,handle_share,appid,can_refund_givemoney,can_refund_integral,can_refund_money,refundmoney,allinpay_orderid,lasttime,accountid,ismessage,orderfeesid,channel,pay_mer_appid,pay_mer_key,refundstatus,fuelcard,account,card,cardnumber,classid,company,companyid,csid,guns,icnumber,integral,iscredit,oil,opener,platenumber,station,user,ictype,fuelid,linkid,goods_orderno,recharge_grouprule,phonei,recharge_stationid,is_sale" \
  -f "/opt/output/" \
  --file-regular-expression '.*.csv'

在这个命令中,-c 参数后面跟的是一个逗号分隔的列名列表,这些列名必须与目标表中的列名严格匹配。确保源文件中的列顺序与目标表中的列顺序一致,或者按照实际需要进行调整。

2. 使用 CSV 文件头信息

如果您的 CSV 文件包含列头信息(即第一行是列名),obloader 可以自动识别并映射这些列名到目标表中的相应列。确保源文件的第一行是列名,并且这些列名与目标表中的列名完全一致。

示例 CSV 文件头:

id,authcode,countprice,createtime,customertype,disable,discount,...

3. 预处理 CSV 文件

如果源文件和目标表之间的列名或顺序不一致,可以在导入前使用脚本(如 Python、Perl 等)对 CSV 文件进行预处理,重新排列列顺序或重命名列,使其与目标表完全匹配。

示例 Python 脚本:

import csv

source_file = '/path/to/source.csv'
target_file = '/path/to/target.csv'

with open(source_file, 'r') as infile, open(target_file, 'w', newline='') as outfile:
    reader = csv.DictReader(infile)
    fieldnames = ['id', 'authcode', 'countprice', 'createtime', ...]  # 按照目标表的列顺序
    writer = csv.DictWriter(outfile, fieldnames=fieldnames)
    writer.writeheader()
    for row in reader:
        writer.writerow({k: row.get(k, '') for k in fieldnames})

4. 使用 INSERT INTO ... SELECT 语句

如果您有权限直接操作数据库,可以考虑将数据从导出的 CSV 文件加载到一个临时表中,然后使用 INSERT INTO ... SELECT 语句将数据插入到目标表中,并在此过程中进行列映射。

示例 SQL 语句:

INSERT INTO target_table (id, authcode, countprice, createtime, ...)
SELECT id, authcode, countprice, createtime, ...
FROM temp_table;

总结

为了手动指定源文件列与目标表列的对应关系,您可以:

  • 使用 obloader-c--columns 参数。
  • 确保 CSV 文件包含正确的列头信息。
  • 在导入前预处理 CSV 文件以匹配目标表结构。
  • 使用 SQL 语句进行数据迁移时进行列映射。

希望这些建议能帮助您解决问题。如果还有其他疑问或需要进一步的帮助,请随时联系 OceanBase 的人工答疑团队获取更多支持。

更多信息请查看:

  1. 使用 SQL 命令进行数据迁移
  2. 插入数据
  3. oceanbase.DBA_OB_IMPORT_TABLE_TASKS
  4. OceanBase 术语
  5. 查询 Agent 未完成的任务
  6. oceanbase.CDB_OB_BACKUP_SET_FILES
  7. oceanbase.DBA_OB_BACKUP_SET_FILES
  8. 查询所有未完成的任务
  9. ob_table_access_policy
  10. oceanbase.CDB_OB_RECOVER_TABLE_JOBS

(小助手的答复已结束,如未能解决您的问题,请继续提问并等待其他同学的回复,谢谢!)

听起来是部分行的数据有缺失吧?能看下异常行的数据有什么区别吗

加了之后就提示连不上数据库了

现在没有–columns这个参数了

表结构sc_order_ob_test_copy1 提供一下

CREATE TABLE sc_order_ob_test_copy1 (
id bigint(20) NOT NULL AUTO_INCREMENT,
authcode bigint(20) DEFAULT NULL,
countprice decimal(19,2) DEFAULT NULL,
createtime datetime NOT NULL,
customertype int(11) DEFAULT NULL,
disable int(11) DEFAULT NULL,
discount decimal(19,2) DEFAULT NULL,
follow_ticket varchar(255) DEFAULT NULL,
follow_ticket_time datetime DEFAULT NULL,
iccard varchar(255) DEFAULT NULL,
invoice_time datetime DEFAULT NULL,
invoice_title varchar(255) DEFAULT NULL,
invoice_type varchar(255) DEFAULT NULL,
is_comment int(11) DEFAULT NULL,
is_invoice int(11) DEFAULT NULL,
isbill int(11) NOT NULL,
mj_coupon_discount decimal(19,2) DEFAULT NULL,
mj_discount decimal(19,2) DEFAULT NULL,
name varchar(255) DEFAULT NULL,
native_orderno varchar(255) DEFAULT NULL,
number decimal(19,2) DEFAULT NULL,
openid varchar(255) DEFAULT NULL,
order_type int(11) DEFAULT NULL,
orderno varchar(255) NOT NULL,
paymoney decimal(19,2) DEFAULT NULL,
payname varchar(255) DEFAULT NULL,
paysource int(11) DEFAULT NULL,
paystatus int(11) DEFAULT NULL,
paystatustime datetime DEFAULT NULL,
paytime datetime DEFAULT NULL,
port varchar(255) DEFAULT NULL,
price decimal(19,2) DEFAULT NULL,
remind varchar(3000) DEFAULT NULL,
sourcetype int(11) DEFAULT NULL,
spid int(11) DEFAULT NULL,
sta_coupon_discount decimal(19,2) DEFAULT NULL,
sta_discount decimal(19,2) DEFAULT NULL,
state int(11) DEFAULT NULL,
taxnumber varchar(255) DEFAULT NULL,
third_content longtext DEFAULT NULL,
third_orderno varchar(255) DEFAULT NULL,
updatetime datetime DEFAULT NULL,
cardid bigint(20) DEFAULT NULL,
class_shift bigint(20) DEFAULT NULL,
gun bigint(20) DEFAULT NULL,
mj_promotionid bigint(20) DEFAULT NULL,
oligasid bigint(20) DEFAULT NULL,
openeruserid bigint(20) DEFAULT NULL,
plateid bigint(20) DEFAULT NULL,
promotionid bigint(20) DEFAULT NULL,
rechargeid bigint(20) DEFAULT NULL,
stationid bigint(20) DEFAULT NULL,
userid bigint(20) DEFAULT NULL,
vcardid bigint(20) DEFAULT NULL,
paylabel varchar(255) DEFAULT NULL,
platform_price decimal(19,2) DEFAULT NULL,
pay_mer_no varchar(255) DEFAULT NULL,
remark text DEFAULT NULL,
univalent decimal(19,2) DEFAULT NULL,
use_balance decimal(19,2) DEFAULT NULL,
use_givebalance decimal(19,2) DEFAULT NULL,
radio_iccard bigint(20) DEFAULT NULL,
finishactivity int(11) DEFAULT NULL,
handle_give int(11) DEFAULT NULL,
pay_promotionid bigint(20) DEFAULT NULL,
pay_pro_discount decimal(19,2) DEFAULT NULL,
handle_share int(11) DEFAULT NULL,
appid bigint(20) DEFAULT NULL,
can_refund_givemoney decimal(19,2) DEFAULT NULL,
can_refund_integral bigint(20) DEFAULT NULL,
can_refund_money decimal(19,2) DEFAULT NULL,
refundmoney decimal(19,2) DEFAULT NULL,
allinpay_orderid bigint(20) DEFAULT NULL,
lasttime timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
accountid bigint(20) DEFAULT NULL,
ismessage int(11) DEFAULT NULL,
orderfeesid bigint(20) DEFAULT NULL,
channel int(11) DEFAULT NULL,
pay_mer_appid varchar(255) DEFAULT NULL,
pay_mer_key varchar(3000) DEFAULT NULL,
refundstatus int(11) DEFAULT NULL,
fuelcard varchar(255) DEFAULT NULL,
account varchar(255) DEFAULT NULL,
card varchar(255) DEFAULT NULL,
cardnumber varchar(255) DEFAULT NULL,
classid bigint(20) DEFAULT NULL,
company varchar(255) DEFAULT NULL,
companyid bigint(20) DEFAULT NULL,
csid bigint(20) DEFAULT NULL,
guns int(11) DEFAULT NULL,
icnumber varchar(255) DEFAULT NULL,
integral decimal(19,2) DEFAULT NULL,
iscredit int(11) DEFAULT NULL,
oil varchar(255) DEFAULT NULL,
opener varchar(255) DEFAULT NULL,
platenumber varchar(255) DEFAULT NULL,
station varchar(255) DEFAULT NULL,
user varchar(255) DEFAULT NULL,
ictype int(11) DEFAULT NULL,
fuelid bigint(20) DEFAULT NULL,
linkid bigint(20) DEFAULT NULL,
goods_orderno varchar(255) DEFAULT NULL,
recharge_grouprule bigint(20) DEFAULT NULL,
phonei bigint(20) DEFAULT NULL,
recharge_stationid bigint(20) DEFAULT NULL,
is_sale varchar(255) DEFAULT NULL,
begintime datetime DEFAULT NULL COMMENT ‘提枪时间’,
start_pressure decimal(9,0) DEFAULT NULL,
end_pressure decimal(9,0) DEFAULT NULL,
PRIMARY KEY (id, createtime),
UNIQUE KEY UK_af4dnlqcgv1ruqqmwb7th6n7u (orderno, createtime) BLOCK_SIZE 16384 LOCAL,
KEY lasttime_paystatus (lasttime, paystatus, stationid) BLOCK_SIZE 16384 LOCAL,
KEY order_paytime (paytime, vcardid, paystatus, order_type, stationid) BLOCK_SIZE 16384 LOCAL,
KEY fuelcard (fuelcard) BLOCK_SIZE 16384 LOCAL,
KEY idx_vcardid_ordertype_createtime_number (vcardid, order_type, createtime, number) BLOCK_SIZE 16384 LOCAL,
KEY idx_gun_stationid_paystatus_sourcetype_createtime (gun, stationid, paystatus, sourcetype, createtime) BLOCK_SIZE 16384 LOCAL,
KEY order_create_station (createtime, stationid) BLOCK_SIZE 16384 LOCAL,
KEY sfc (stationid, fuelid, classid) BLOCK_SIZE 16384 LOCAL,
KEY plateid (plateid) BLOCK_SIZE 16384 LOCAL,
KEY idx_stationid_ordertype_paystatus_state_createtime_paymoney (stationid, order_type, paystatus, state, createtime, paymoney) BLOCK_SIZE 16384 LOCAL,
KEY FK5w74p9tsat109r3q5c9xth7ln (appid) BLOCK_SIZE 16384 LOCAL,
KEY FKjufoy2gme1u80mb62q31ecb61 (userid, plateid) BLOCK_SIZE 16384 LOCAL,
KEY idx_gun_stationid_paystatus_state_createtime_orderno (gun, stationid, paystatus, state, createtime, orderno) BLOCK_SIZE 16384 LOCAL,
KEY FKrfhtj7ugwwmteesgcik7tauku (cardid) BLOCK_SIZE 16384 LOCAL,
KEY idx_vcardid_customertype_paystatus_state_createtime_paymoney (vcardid, customertype, paystatus, state, createtime, paymoney) BLOCK_SIZE 16384 LOCAL,
KEY FKm3unsqwq81wq9rneeam63097e (class_shift) BLOCK_SIZE 16384 LOCAL,
KEY idx_vcardid_paystatus_ordertype (vcardid, paystatus, order_type) BLOCK_SIZE 16384 LOCAL
) AUTO_INCREMENT = 116882590 AUTO_INCREMENT_MODE = ‘ORDER’ DEFAULT CHARSET = utf8mb4 ROW_FORMAT = DYNAMIC COMPRESSION = ‘zstd_1.3.8’ REPLICA_NUM = 1 BLOCK_SIZE = 16384 USE_BLOOM_FILTER = FALSE TABLET_SIZE = 134217728 PCTFREE = 0
partition by range columns(createtime)
(partition p2018_q1 values less than (‘2018-04-01 00:00:00’),
partition p2018_q2 values less than (‘2018-07-01 00:00:00’),
partition p2018_q3 values less than (‘2018-10-01 00:00:00’),
partition p2018_q4 values less than (‘2019-01-01 00:00:00’),
partition p2019_q1 values less than (‘2019-04-01 00:00:00’),
partition p2019_q2 values less than (‘2019-07-01 00:00:00’),
partition p2019_q3 values less than (‘2019-10-01 00:00:00’),
partition p2019_q4 values less than (‘2020-01-01 00:00:00’),
partition p2020_q1 values less than (‘2020-04-01 00:00:00’),
partition p2020_q2 values less than (‘2020-07-01 00:00:00’),
partition p2020_q3 values less than (‘2020-10-01 00:00:00’),
partition p2020_q4 values less than (‘2021-01-01 00:00:00’),
partition p2021_q1 values less than (‘2021-04-01 00:00:00’),
partition p2021_q2 values less than (‘2021-07-01 00:00:00’),
partition p2021_q3 values less than (‘2021-10-01 00:00:00’),
partition p2021_q4 values less than (‘2022-01-01 00:00:00’),
partition p2022_q1 values less than (‘2022-04-01 00:00:00’),
partition p2022_q2 values less than (‘2022-07-01 00:00:00’),
partition p2022_q3 values less than (‘2022-10-01 00:00:00’),
partition p2022_q4 values less than (‘2023-01-01 00:00:00’),
partition p2023_q1 values less than (‘2023-04-01 00:00:00’),
partition p2023_q2 values less than (‘2023-07-01 00:00:00’),
partition p2023_q3 values less than (‘2023-10-01 00:00:00’),
partition p2023_q4 values less than (‘2024-01-01 00:00:00’),
partition p2024_q1 values less than (‘2024-04-01 00:00:00’),
partition p2024_q2 values less than (‘2024-07-01 00:00:00’),
partition p2024_q3 values less than (‘2024-10-01 00:00:00’),
partition p2024_q4 values less than (‘2025-01-01 00:00:00’),
partition p2025_q1 values less than (‘2025-04-01 00:00:00’),
partition p2025_q2 values less than (‘2025-07-01 00:00:00’),
partition p2025_q3 values less than (‘2025-10-01 00:00:00’),
partition p2025_q4 values less than (‘2026-01-01 00:00:00’));

你好 csv文件数据提供一下 我们内部测试一下

我是用–auto-column-mapping基本都能导入,只有两条记录好像有问题,加不进去,但是我不知道是那两条,ob-loader-dumper.bad日志里也没找到,csv文件也很大,1个G呢

解决了,看到有问题的两条数据了,是因为插入的时间不在某个分区里

好的 在有问题 问答区发帖交流