sqoop 的使用

1)列出mysql数据库中的所有数据库命令
sqoop list-databases --connect jdbc:mysql://localhost:3306/ --username root --password 123456

2)连接mysql并列出数据库中的表命令
sqoop list-tables --connect jdbc:mysql://localhost:3306/test --username root --password 123456
命令中的test为mysql数据库中的test数据库名称 username password分别为mysql数据库的用户密码

3)将关系型数据的表结构复制到hive中
sqoop create-hive-table --connect jdbc:mysql://localhost:3306/test --table username --username root --password 123456 --hive-table test
其中 --table username为mysql中的数据库test中的表 --hive-table test 为hive中新建的表名称

4)从关系数据库导入文件到hive中
sqoop import --connect jdbc:mysql://localhost:3306/test --username root --password mysql-password --table t1 --hive-import

5)将hive中的表数据导入到mysql中
sqoop export --connect jdbc:mysql://localhost:3306/test --username root --password admin --table uv_info --export-dir /user/hive/warehouse/uv/dt=2011-08-03

6)上传数据到hdfs中
sqoop import --connect jdbc:mysql://10.2.136.24:3306/test --username root --table aa -m 1

7)将数据从关系数据库导入文件到hive表中,--query 语句使用
sqoop import --append --connect jdbc:mysql://192.168.20.118:3306/test --username dyh --password 000000 --query "select id,age,name from userinfos where \$CONDITIONS" -m 1 --target-dir /user/hive/warehouse/userinfos2 --fields-terminated-by ",";

8)将数据从关系数据库导入文件到hive表中,--columns --where 语句使用
sqoop import --append --connect jdbc:mysql://192.168.20.118:3306/test --username dyh --password 000000 --table userinfos --columns "id,age,name" --where "id > 3 and (age = 88 or age = 80)" -m 1 --target-dir /user/hive/warehouse/userinfos2 --fields-terminated-by ",";

注意:--target-dir /user/hive/warehouse/userinfos2 可以用 --hive-import --hive-table userinfos2 进行替换
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值