sqoop基本命令
2016-03-25 16:37
453 查看
sqoop连接
sqoop import –connect jdbc:mysql://localhost/db –username name –password 12345
手动指定驱动
–driver com.microsoft.jdbc.sqlserver.SQLServerDriver
数据导入hive
–hive-import
写sql语句导入
–query ‘select * frome tab’
手动设置参数
sqoop import -D property.name=property.value …
导入目标目录
–target-dir
并发数量
-m ${parallel_count}
导出
export
通过某个字段分割
默认是主键,假设有100行数据,它会执行那个SELECT * FROM sometable WHERE id >= lo AND id < hi, with (lo, hi) 会分为4次导入(0,250),(250,500),(500,750),(750,1001)。如果这个字段不能达到实际的划分区域的效果,可以用别的字段。如果没有索引列或者是组合主键的表,需要手动设置一个划分列
–split-by
转换为对象
–map-column-java 转换为java数据类型
–map-column-hive 转转为hive数据类型
hive空值处理
sqoop会自动把NULL转换为null处理,但是hive中默认是把\N来表示null,因为预先处理不会生效的
我们需要使用 –null-string 和 –null-non-string来处理空值 把\N转为\N
sqoop import … –null-string ‘\N’ –null-non-string ‘\N’
hive导入参数
–hive-home 重写$HIVE_HOME
–hive-import 插入数据到hive当中,使用hive的默认分隔符
–hive-overwrite 重写插入
–create-hive-table 建表,如果表已经存在,该操作会报错!
–hive-table 设置到hive当中的表名
–hive-drop-import-delims 导入到hive时删除 \n, \r, and \01
–hive-delims-replacement 导入到hive时用自定义字符替换掉 \n, \r, and \01
–hive-partition-key hive分区的key
–hive-partition-value hive分区的值
–map-column-hive 类型匹配,sql类型对应到hive类型
如果存在就更新,不存在就插入
–update-mode allowinsert
导入所有的表sqoop-import-all-tables
每个表都要有主键,不能使用where条件过滤
sqoop import-all-tables –connect jdbc:mysql://db.foo.com/corp
增加导入
–check-column (col) 指定需要导入的列
–incremental (mode) 指定哪一行是新值并指定筛选新值模式
–last-value (value) 前一次导入数据中某列的最大值
direct是为了利用某些数据库本身提供的快速导入导出数据的工具,比如mysql的mysqldump性能比jdbc更好,使用的时候,那些快速导入的工具的客户端必须在shell脚本的目录下
sqoop import –connect jdbc:mysql://server.foo.com/db –table bar –direct –default-character-set=latin1
sqoop import –connect jdbc:mysql://localhost/db –username name –password 12345
手动指定驱动
–driver com.microsoft.jdbc.sqlserver.SQLServerDriver
数据导入hive
–hive-import
写sql语句导入
–query ‘select * frome tab’
手动设置参数
sqoop import -D property.name=property.value …
导入目标目录
–target-dir
并发数量
-m ${parallel_count}
导出
export
通过某个字段分割
默认是主键,假设有100行数据,它会执行那个SELECT * FROM sometable WHERE id >= lo AND id < hi, with (lo, hi) 会分为4次导入(0,250),(250,500),(500,750),(750,1001)。如果这个字段不能达到实际的划分区域的效果,可以用别的字段。如果没有索引列或者是组合主键的表,需要手动设置一个划分列
–split-by
转换为对象
–map-column-java 转换为java数据类型
–map-column-hive 转转为hive数据类型
hive空值处理
sqoop会自动把NULL转换为null处理,但是hive中默认是把\N来表示null,因为预先处理不会生效的
我们需要使用 –null-string 和 –null-non-string来处理空值 把\N转为\N
sqoop import … –null-string ‘\N’ –null-non-string ‘\N’
hive导入参数
–hive-home 重写$HIVE_HOME
–hive-import 插入数据到hive当中,使用hive的默认分隔符
–hive-overwrite 重写插入
–create-hive-table 建表,如果表已经存在,该操作会报错!
–hive-table 设置到hive当中的表名
–hive-drop-import-delims 导入到hive时删除 \n, \r, and \01
–hive-delims-replacement 导入到hive时用自定义字符替换掉 \n, \r, and \01
–hive-partition-key hive分区的key
–hive-partition-value hive分区的值
–map-column-hive 类型匹配,sql类型对应到hive类型
如果存在就更新,不存在就插入
–update-mode allowinsert
导入所有的表sqoop-import-all-tables
每个表都要有主键,不能使用where条件过滤
sqoop import-all-tables –connect jdbc:mysql://db.foo.com/corp
增加导入
–check-column (col) 指定需要导入的列
–incremental (mode) 指定哪一行是新值并指定筛选新值模式
–last-value (value) 前一次导入数据中某列的最大值
direct是为了利用某些数据库本身提供的快速导入导出数据的工具,比如mysql的mysqldump性能比jdbc更好,使用的时候,那些快速导入的工具的客户端必须在shell脚本的目录下
sqoop import –connect jdbc:mysql://server.foo.com/db –table bar –direct –default-character-set=latin1
相关文章推荐
- 分享Hive的一份胶片资料
- Hadoop生态上几个技术的关系与区别:hive、pig、hbase 关系与区别
- 将Hive的默认数据库Derby改为Postgresql
- kettle中对hive操作时需要知道的东西
- Hive安装配置
- sqoop使用mysql做为metastore
- Hive - truncate partition、drop partition 区别
- #Note# Analyzing Twitter Data with Apache Hadoo...
- 问题记录:[Sqoop]
- [翻译]Hive wiki GettingStarted
- hive命令积累
- 启动hive命令报错 “Metastore contains multiple versions”
- sparksql与hive整合
- hive on spark 编译
- sqoop 中文文档 User guide 一
- sqoop 中文文档 User guide 二 import
- sqoop 中文文档 User guide 二 import续
- Using Sqoop 1.4.6 With Hadoop 2.7.4
- How To Use Sqoop2 Increment Import