使用Sqoop将数据从Hive导入MySQL可能遇到的问题

xiaoxiao2021-02-28  35

使用Sqoop将数据从Hive导入MySQL可能遇到的问题
2017年07月13日 20:31:34 阅读数:1191

1.权限问题

|--问题描述

Java.io.IOException: com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:

Caused by: com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:

|--解决方法

解决MySQL的授权问题。

类似如下:

grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option;*.*代表所有数据库的所有表。identified by 'root' root是密码。

可以授予的权限有:select insert update delete create drop index alter grant references reload shutdown process file...14个权限。

不要忘记flush privileges;

2.不能导出数据

|--问题描述

java.io.IOException: Can’t export data, please check task tracker logs

Caused by: java.util.NoSuchElementException

|--解决方法

导出数据到MySQL,当然数据库表要先存在,否则会报错,此错误的原因为sqoop解析文件的字段与MySql数据库的表的字段对应不上造成的。因此需要在执行的时候给sqoop增加参数,告诉sqoop文件的分隔符,使它能够正确的解析文件字段。hive默认的字段分隔符为'\001',sqoop的默认分隔符是 ','。

|--问题描述

java.io.IOException: Can’t export data, please check task tracker logs Caused by: java.lang.NumberFormatException: For input string: “665A5FFA-32C9-9463-1943-840A5FEAE193″

|--解决方法

指定null字段的填充符

--input-null-string:如果没有这个选项,那么在字符串类型列中,字符串"null"会被转换成空字符串,所以最好写上这个,指定为'\\N'

--input-null-non-string:如果没有这个选项,那么在非字符串类型的列中,空串和"null"都会被看作是null

|--问题描述

java.io.IOException: Can’t export data, please check task tracker logs

Caused by: java.lang.IllegalArgumentException

|--解决方法

hive中字符串必须是yyyy-mm-dd

3.字段格式问题

|--问题描述

java.io.IOException: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column ‘pid’ at row 1 Caused by: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column ‘pid’ at row 1

|--解决方法

hive中定义的表字段属性与mysql中定义的字段属性不一致,导致mysql数据库中的个别字段存不下
转载请注明原文地址: https://www.6miu.com/read-2650240.html

最新回复(0)