结合Sqoop练习一下columns、where和query参数

1、前期的数据准备

1》创建一个学生表

create table student(id char(30),name char(30),age int,phone char(100),address char(100));

2》插入数据

insert into student values("1001","zhanghuan","21","1111","guiyang");

insert into student values("1002","weitiao","24","1112","baiyun");

insert into student values("1003","tanqian","18","1113","panzhou");

insert into student values("1004","hexiong","17","1114","neimeng");

查询显示:

3》使用ETL工具Sqoop,将MySQL数据库db03中的student表的数据导入到大数据平台的Hive中。

sqoop import -connect jdbc:mysql://hadoop:3306/db03 -username sqoop03 -password 123456 -table student -hive-import -hive-table myhive.student1 -m 1

2、columns的用法

1》将mysql中student表中的id,name,age字段写入hive表中:

sqoop import -connect jdbc:mysql://hadoop:3306/db03 -username sqoop03 -password 123456 -table student -hive-import -hive-table myhive.student2 -m 1 -columns 'name,id,age'

3. where的用法

1》将mysql中的student表中的学习名字以z或者h开头的学生信息导入到hive表中

sqoop import -connect jdbc:mysql://hadoop:3306/db03 -username sqoop03 -password 123456 --target-dir student -hive-import -hive-table myhive.student3 -m 1 -query "select * from student where name like 'z%'||name like 'h%' and \$CONDITIONS"

4、query的用法

1》 将mysql中的student表中的年龄大于21且地址为baiyun的学生信息导入到hive表中

sqoop import -connect jdbc:mysql://hadoop:3306/db03 -username sqoop03 -password 123456 --target-dir student -query "select * from student where age>21 &&address= 'baiyun' and \$CONDITIONS" -hive-import -hive-table myhive.student4 -m 1

5、 可以http://192.168.10.130:9870下看见从mysql导入的表

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

墨染盛夏呀

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值