mysql导入bom_csv 文件 BOM(Byte Order Mark) 的去除以及 MySQL 的导入

Windows 上的 Excel 导出 csv 文件时,默认添加了 BOM,这个 BOM 的全称是 Byte Order Mark,以前的机器有字节顺序的问题,Windows 至今都没有去掉这个 BOM 头。这在 Linux 下导入 CSV 文件时会报字段格式有错。

The UTF-8 BOM is a sequence of Bytes at the start of a text-stream (EF BB BF) that allows the reader to more reliably guess a file as being encoded in UTF-8.

Normally, the BOM is used to signal the endianness of an encoding, but since endianness is irrelevant to UTF-8, the BOM is unnecessary.

According to the Unicode standard, the BOM for UTF-8 files is not recommended:

解决的办法是 (选任意一种方法)

1. tail -c +4 orig.txt > withoutBOM.txt

2. dos2unix orig.txt

3. sed -i '1s/^\xEF\xBB\xBF//' orig.txt

然后,我们用 以下命令就可以把 csv 文件导入到对应的数据库表了。

LOAD DATA INFILE ‘file’

IGNORE INTO TABLE table

CHARACTER SET UTF8

FIELDS TERMINATED BY ‘;’

OPTIONALLY ENCLOSED BY ‘”‘

LINES TERMINATED BY ‘\n’

作者: 甬洁网络

--移动互联网&物联网技术提供商 查看甬洁网络的所有文章

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值