1.导入导出数据区分
导入:关系型数据库到hdfs上
导出:hdfs到关系型数据库
导入导出与参数位置没关系!!!
2.sqoop用法手册:
http://sqoop.apache.org/docs/1.4.6/SqoopUserGuide.html
3.导入数据
3 .1导入全部数据
bin/sqoop import \ -- bin/sqoop启动命令 import 导入
--connect jdbc:mysql://node01:3306/userdb \
--username root \
--password 123456\
--table emp_add \ -- 导出的数据表
--target-dir /sqoop/user \ -- 导出的目录
--delete-target-dir \ -- 如果存在就删除该目录(公司工作慎用!!!)
-- num-mappers 1 \ -- 定义map数
--fileds-terminated-by "\t" -- 指定文件的分隔符
3.2自定义查询导入
bin/sqoop import \ -- bin/sqoop启动命令 import 导入
--connect jdbc:mysql://node01:3306/userdb \
--username root \
--password 123456\
--target-dir /sqoop/user \
--delete-target-dir \
-- num-mappers 1 \
--fileds-terminated-by "\t"
--query ‘select id,hno,street,city from emp_add where id <=1 and $CONDITIONS;‘
(双引号: “select id,hno,street,city from emp_add where id <=1 and \$CONDITIONS;“)需要转义一下
3.3导入指定的列
3.4关键字筛选查询导入数据
where
’
where+指定列
3.5导入到hive中
实际动作是mysql-->hdfs-->hive 分为了两步
4.导出数据
4.1hive/hdfs导出
4.2
5.脚本打包
定时执行任务!!!
创建.opt文件
编写sqoop脚本
执行脚本