注:db02为在sqoop02中创建的数据库,student为在db02数据库中创建的表
Bigdata02为在hive下创建的数据库,mycolumns01为获取筛选结果后自动生成的表。
- columns的使用
- 上传筛选数据到hive的bigdata.mycolumns里
sqoop import -connect jdbc:mysql://192.168.43.216:3306/db02 -username sqoop02 -password 123456 -table student -hive-import -hive-table bigdata02.mycolumns01 -m 1 --columns 'id,age'
- 上传成功:
- where的使用
- 抽取年龄为20的人的信息:
sqoop import -connect jdbc:mysql://192.168.43.216:3306/db02 -username sqoop02 -password 123456 -table student -hive-import -hive-table bigdata02.mycolumns02 -m 1 --columns 'id,age' --where ‘age=20’
2.创建成功:
- query的使用
- 自定义SQL的方式导入的用法:
sqoop import -connect jdbc:mysql://192.168.43.216:3306/db02 -username sqoop02 -password 123456 --target-dir student01 -hive-import -hive-table bigdata02.mycolumns04 -m 1 --query "select id,name from student where age=20 and \$CONDITIONS"
2.创建脚本:
脚本内容:
hdfs dfs -rm -r hdfs://HadoopMaster:9000/user/hadoop/student01
sqoop import -connect jdbc:mysql://192.168.43.216:3306/db02 -username sqoop02 -password 123456 --target-dir student01 -hive-import -hive-table bigdata02.mycolumns04 -m 1 --query "select id,name from student where age=20 and \$CONDITIONS"
- 给脚本赋权:
- 执行脚本:
- 执行成功: