一、import命令
1.将mysql表test中的数据导入hive的hivetest表,hive的hivetest表不存在
sqoop import --connect jdbc:mysql://192.168.1.111:3306/test --username hive
--password hive --table test --hive-table hivetest --hive-import -m 1
2.在1的基础上,分别进行overwrite导入和into(直接加入)导入
into:命令同1
overwrite:
sqoop import --connect jdbc:mysql://192.168.1.111:3306/test --username hive
--password hive --table test --hive-table hivetest --hive-import -m 1 --hive-overwrite
3.在2的基础上,通过增加mysql的test表数据,增量导入到hive表中
sqoop import --connect jdbc:mysql://192.168.1.111:3306/test --username hive
--password hive --table test --where "id>3" --hive-table hivetest --hive-import -m 1
或者
sqoop import --connect jdbc:mysql://192.168.1.111:3306/test --username hive
--password hive --table test --query "select id,name from test where id>3" --hive-table hivetest --hive-import -m 1
4.将test表中数据导出到使用','分割字段的hive表中(hivetest2)中
创建表:create table hivetest2(id int,name string) row format delimited fields terminated by ',';
sqoop:
sqoop import --connect jdbc:mysql://192.168.1.111:3306/test --username hive --password hive --table test
--hive-table hivetest2 --hive-import -m 1 --fields-terminated-by ","
5.将test表中数据导入到hdfs中。
sqoop import --connect jdbc:mysql://192.168.1.111:3306/test --username hive --password hive --table test
--target-dir /test -m 1
6.在5的基础上,增量导出数据到hdfs中
sqoop import --connect jdbc:mysql://192.168.1.111:3306/test --username hive --password hive
--table test --target-dir /test -m 1 --check-column id --incremental append --last-value 11
二、export命令
1.将hdfs上的文件导出到关系型数据库test2表中
sqoop export --connect jdbc:mysql://192.168.1.111:3306/test --username hive --password hive
--table test2 --export-dir /test
2.将hive表(hivetest)数据导出到关系型数据库test2表中(使用insertOrUpdate方法导入)
hivetest表分割方式是'\u0001',但是export命令默认使用','分割数据
sqoop export --connect jdbc:mysql://192.168.1.111:3306/test --username hive --password hive
--table test2 --export-dir /hive/hivetest --input-fields-terminated-by "\\01" --update-mode
allowinsert --update-key id