【问题标题】:sqoop export specific columns from hdfs to mysqlsqoop 将特定列从 hdfs 导出到 mysql
【发布时间】:2013-10-10 07:15:56
【问题描述】:

SQOOP 是否支持将特定列从 hdfs 导出到 mysql?

例如现在我有一个这样的 hdfs 文件:

866138000211400 4   com.spreadst.validationtools    1   1310090804  0   0
866138000211400 4   com.spreadst.validdate  1   1310090804  0   0
866138000211400 4   com.spreadtrum.android.eng  1   1310090804  0   0
866138000211400 4   com.tencent.mm  261 1310090804  0   0
866138000211400 4   com.tencent.mobileqq    13  1310090804  0   0
866138000211400 4   com.thunderst.radio 1   1310090804  0   0
866138000211400 4   com.uucun51111531.android.cms   2013080901  1310090804  0   0
866138000211400 4   com.yeezonetech.firewall    1   1310090804  0   0
866138000211400 4   com.youku.phone 41  1310090804  0   0
866138000211400 4   org.openintents.cmfilemanager   20  1310090804  0   0

每行有 7 列(imei、platform、packagename、softversion、gathertime、isHidden、isUninstalled),每列以 '\t' 结尾。

mysql的表结构是这样的: imei:varchar(100), platform:char(1), packagename:varchar(100), softversion:varchar(20).

如何使用 sqoop 直接将 hdfs 文件导出到 mysql 与 4 个特定列?

【问题讨论】:

    标签: mysql sqoop


    【解决方案1】:

    是的,使用 --columns 参数指定要导入的列。

    来自 Sqoop Cookbook 的示例:

        sqoop export \
      --connect jdbc:mysql://mysql.example.com/sqoop \
      --username sqoop \
      --password sqoop \
      --table cities \
      --columns country,city
    

    【讨论】:

      【解决方案2】:
      sqoop import --connect jdbc:mysql://localhost/DataBase_Name \
        --username root --table Table_Name --columns "Col1,Col2" \
        -m 1 --target-dir Hdfs_Dir_Name
      

      【讨论】:

      • 虽然代码很受欢迎,但它应该始终有一个附带的解释。这不必很长,但在意料之中。
      猜你喜欢
      • 2021-11-08
      • 1970-01-01
      • 2013-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-06
      • 1970-01-01
      • 2011-08-16
      相关资源
      最近更新 更多