mysql之sqoop导入数据到hive和hdfs

freeliver54 阅读:83 2023-08-25 12:46:42 评论:0

我们可以用sqoop将数据导入到hdfs和hive中吗? 我已经用两个不同的用户(root 和 admin)试过了 下面是root和admin之间的命令

[根]

sqoop import --connect jdbc:mysql://10.6.162.58/test_alpha --username pbd -P --table posts --hive-import --hive-database test_root --hive-table posts1 --hive-drop-import-delims --null-string '\\N' --null-non-string '\\N' --target-dir test_hive_root/2 

[管理员]

sqoop import --connect jdbc:mysql://10.6.162.58/test_alpha --username pbd -P --table posts --hive-import --hive-database test_admin --hive-table posts1 --hive-drop-import-delims --null-string '\\N' --null-non-string '\\N' --target-dir test_hive_admin/2 

它返回:

两种方式都成功导入数据到hive,但都无法导入到HDFS。

对于 root,它不会创建我定义的目录“test_hive_root/2”

对于管理员,它只是创建目录“test_hive_admin/2”,但只有已创建的“成功”文件而不是数据(通常当我将其导入 HDFS 时,它会创建“成功”文件和另外 4 个文件)

我该如何解决这个问题? sqoop可以导入HDFS和Hive吗?

请您参考如下方法:

target-dir 控制数据在加载到 Hive 表之前需要临时存储的位置,但不会在该位置创建 Hive 表。

表是在 hive-site.xmlhive.metastore.warehouse.dir 属性中指定的目录中创建的。

如果要导入到特定目录,则使用不带 hive-import 参数的 target-dir 并在 HDFS 目录之上创建配置单元表。

(或)

创建指向目标目录的 Hive 外部表,然后在 sqoop 导入中删除 --create-hive-table 参数和 --target-dir。

在这里阅读答案:https://community.hortonworks.com/questions/198586/running-a-sqoop-job-with-a-target-dir-destination.html

这里:https://community.hortonworks.com/questions/193934/sqoop-import-mssql-table-into-hdfs.html


标签:HDFS
声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

关注我们

一个IT知识分享的公众号