infobright中导入数据避免特殊字符问题

目前在用的是社区版的infobright,不支持DML功能,只能用LOAD DATA方式导入数据。

如果元数据中有特殊控制字符,导入过程中经常会报错,很是恼火。应对策略有两种方法:

  1. 设置Reject File导入之前,设定 @BH_REJECT_FILE_PATH 和 @BH_ABORT_ON_COUNT 就可以忽略多少条导入失败的记录,并且将这些记录保存在指定文件
    /** when the number of rows rejected reaches 10, abort process **/
    
    set @BH_REJECT_FILE_PATH = '/tmp/reject_file';
    
    set @BH_ABORT_ON_COUNT = 10;
    
    BH_ABORT_ON_COUNT 设定为 -1 的话,表示永不忽略。

    也可以设置 BH_ABORT_ON_THRESHOLD 选项,该选项表示有最多多少百分比的数据允许被忽略,因此该选项的值是小数格式,例如 BH_ABORT_ON_THRESHOLD = 0.03(表示3%)

  2. 导出时指定结束符此外,还可以在导出数据时制定结束符,并且设定忽略哪些转义字符(\、”、’ 等字符),例如:
select fields_list... into outfile '/tmp/outfile.csv' fields terminated by '||' ESCAPED BY '\\' lines terminated by '\r\n' from mytable;
  1. 或者,将行间隔符设定为其他特殊标识,例如:select fields_list… into outfile ‘/tmp/outfile.csv’ fields terminated by ‘||’ ESCAPED BY ‘\\’ lines terminated by ‘$$$$$\r\n’ from mytable;当然了,这种情况下,实际数据行中就不能存在 “$$$$$\r\n” 这个值了,否则会被当成换行标识。

发表评论

电子邮件地址不会被公开。

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax

Time limit is exhausted. Please reload CAPTCHA.