hive sqoop常用命令

来源:互联网 发布:网络连接中断 编辑:程序博客网 时间:2024/04/26 10:20

------------------------------------import------------------------------------------
//其中hive是我的数据库名
1、sqoop import-all-tables --connect jdbc:mysql://192.168.10.103/hive1704 -username=root \
-password=123456  导入这个mysql库下面的所有表及表数据 如果要换行 用 "\" 换行转译/

2、sqoop import -connect jdbc:mysql://192.168.10.11/hive -username=root \
-password=123456  -table test02
导出指定库下的表中的数据

3、sqoop import -connect jdbc:mysql://192.168.10.11/hive -username=root \
-password=123456 -table test02 -target-dir /bigdata/mysqoop1704/test02
指定HDFS位置导出数据库指定表数据

4、sqoop import -connect jdbc:mysql://192.168.10.11/hive -username=root \
-password=123456 -table test02 -target-dir /bigdata/mysqoop1704/test03 \
-fields-terminated-by '\t'
导出指定库指定表指定HDFS路径的指定了分隔符的数据

5、sqoop import -connect jdbc:mysql://192.168.10.11/hive -username=root \
-P -table test02 -target-dir /bigdata/mysqoop1704/test04 \
-fields-terminated-by '\t'
不要显示的输入密码,从控制台输入

6、sqoop import -connect jdbc:mysql://192.168.10.11/hive -username=root \
-P -table test02 -target-dir /bigdata/mysqoop1704/test05 \
-fields-terminated-by '\t' -m 1
指定输出文件的数量

7、sqoop import -connect jdbc:mysql://192.168.10.11/hive -username=root \
-P -table test02 -columns "name" -target-dir /bigdata/mysqoop1704/test06 \
-m 1
指定导出表中的些列数据"col1,col2,col3"

8、sqoop import -connect jdbc:mysql://192.168.10.11/hive -username=root \
-P -table test02 -columns "id,name" -where "id>1" \
-target-dir /bigdata/mysqoop1704/test07 \
-fields-terminated-by '\t' -m 1
添加导出的筛选条件中使用sql的where条件

9、sqoop import -connect jdbc:mysql://192.168.10.11/hive -username=root \
-P -query "select * from test02 where \$CONDITIONS" \
-target-dir /bigdata/mysqoop1704/test08 \
-fields-terminated-by '\t' -m 1
使用sql筛选要导出的数据

10、sqoop import -connect jdbc:mysql://192.168.10.11/hive -username=root \
-P -query "select * from test02 where id>1 and \$CONDITIONS" \
-target-dir /bigdata/mysqoop1704/test08 \
-fields-terminated-by '\t' -m 1
where条件后and衔接默认变量,and后面是默认变量

11、sqoop import -connect jdbc:mysql://192.168.10.11/hive -username=root \
-P -query "select * from test02 where id>1 and \$CONDITIONS" \
-split-by "id" \
-target-dir /bigdata/mysqoop1704/test09 \
-fields-terminated-by '\t' -m 2
指定输出文件的个数大于1

12、sqoop create-hive-table -connect jdbc:mysql://192.168.10.11/hive \
-table test02 -username=root -P -hive-table myhivedb01.mysqooptest01
导出mysql表结构到hive库中(对应库建表名ysqooptest01)

13.sqoop import -connect jdbc:mysql://192.168.10.11/hive -username=root --help
帮助文档