一.先创建一个小表(test_01)进行测试(主节点IP:169.254.109.130/oracle服务器IP:169.254.109.100)
1.测试连接oracle;
sqoop list-tables --connect jdbc:oracle:thin:@169.254.109.100/ciicods --username odsuser --password odsuser
2.创建HDFS目录;
sudo -u hdfs hdfs dfs -mkdir /oracle
3.先将oracle中的数据导入HDFS;
sudo -u hdfs sqoop import --connect jdbc:oracle:thin:@169.254.109.100:1521:ciicods --username odsuser --password odsuser \
--table TEST_01 \
--target-dir /oracle/TEST_01 \cd
--fields-terminated-by "\\01" \
--hive-drop-import-delims \
--null-string ‘\\N‘ \
--null-non-string ‘\\N‘ \
-m 1
4.权限控制;
sudo -u hdfs hdfs dfs -chmod -R 777 /oracle/*
5.登录hive创建外部表映射HDFS中的数据;
beeline -u jdbc:hive2://169.254.109.130:10000 -n hive -p 123456
create external table test_01(id int,name varchar2(20))location "/oracle/test_01";
6.查询是否映射到数据;
select * from test_01;
二.从Hive导出表到Oracle
1.在Oracle中创建相应的表,注意字段类型要一致;
2.把hive中的数据写入hdfs
insert overwrite directory ‘/user/senior/hive/exp_hive ‘select * from emp ;
sqoop export
--table demo01
--connect jdbc:oracle:thin:@192.168.43.246:1521:ciicods
--username odsuser --password odsuser
--export-dir /oracledb/tmp1/test
--columns id,name,date_dt
--input-fields-terminated-by ‘,‘
-m 3;
三.参数说明
1.import/export通用
选项 含义说明
--connect
--connection-manager
--driver
--hadoop-mapred-home
--help打印用法帮助信息
--password-file设置用于存放认证的密码信息文件的路径
-P从控制台读取输入的密码
--password
--username
--verbose 打印详细的运行信息
--connection-param-file
2.import
选项 含义说明
--append 将数据追加到HDFS上一个已存在的数据集上
--as-avrodatafile将数据导入到Avro数据文件
--as-sequencefile将数据导入到SequenceFile
--as-textfile将数据导入到普通文本文件(默认)
--boundary-query
--columns
--delete-target-dir如果指定目录存在,则先删除掉
--direct使用直接导入模式(优化导入速度)
--direct-split-size
--fetch-size
--inline-lob-limit
-m,--num-mappers
-e,--query
--split-by
--table
--target-dir
--warehouse-dir
--where
-z,--compress启用压缩
--compression-codec
--null-string
--null-non-string
3.export
选项 含义说明
--validate
--validation-threshold
--direct 使用直接导出模式(优化速度)
--export-dir
-m,--num-mappers
--table
--call
--update-key
--update-mode
--input-null-string
--input-null-non-string
--staging-table
--clear-staging-table清除工作区中临时存放的数据
--batch使用批量模式导出
参数说明链接地址:https://blog.csdn.net/wangmuming/article/details/25303831