sqoop将特定列从hdfs导出到mysql

时间:2013-10-10 07:15:56

标签: mysql sqoop

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

e.g。现在我有一个像这样的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直接将4个特定列导出hdfs文件到mysql?

2 个答案:

答案 0 :(得分:2)

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

来自Sqoop Cookbook的例子:

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

答案 1 :(得分:1)

sqoop import --connect jdbc:mysql://localhost/DataBase_Name \
  --username root --table Table_Name --columns "Col1,Col2" \
  -m 1 --target-dir Hdfs_Dir_Name