首页 > 解决方案 > 我们可以使用 sqoop 导出特殊字符吗?

问题描述

我正在尝试使用 sqoop 导出将其中一张表从配置单元导出到 MySQL。配置单元表数据包含特殊字符。

我的蜂巢“special_char”表数据:

1   じゃあまた
2   どうぞ

我的 Sqoop 命令:

 sqoop export --verbose --connect jdbc:mysql://xx.xx.xx.xxx/Sampledb --username abc --password xyz --table special_char --direct --driver com.mysql.jdbc.Driver  --export-dir /apps/hive/warehouse/sampledb.db/special_char --fields-terminated-by ' '

使用上述 sqoop 导出命令后,数据以问号(???)的形式存储,而不是带有特殊字符的实际消息。

MySql“special_char”表:

id  message
1    ?????
2    ??? 

谁能帮我存储特殊字符而不是问号(???)。

标签: mysqlhivesqoop

解决方案


在 JDBC URL 中指定正确的编码和字符集,如下所示:

jdbc:mysql://xx.xx.xx.xxx/Sampledb?useUnicode=true&characterEncoding=UTF-8

sqoop export --verbose --connect jdbc:mysql://xx.xx.xx.xxx/Sampledb?useUnicode=true&characterEncoding=UTF-8 --username abc --password xyz --table special_char --direct --driver com.mysql.jdbc.Driver  --export-dir /apps/hive/warehouse/sampledb.db/special_char --fields-terminated-by ' '

请验证日文字符的字符集编码并使用正确的字符集。

参考:https ://community.hortonworks.com/content/supportkb/198290/native-sqoop-export-from-hdfs-fails-for-unicode-ch.html


推荐阅读