1.下载sqoop
下载地址:http://ftp.wayne.edu/apache/sqoop/1.4.6/
2.上传,解压
3.配置环境变量
vi /etc/profile
使环境变量生效:
source /etc/profile
4.配置文件
4.1 sqoop-env.sh
先将模板复制或重命名
vi sqoop-env.sh
4.2 添加mysq jar包
cp apache-hive-1.2.1-bin/lib/mysql-connector-java-5.1.45-bin.jar sqoop-1.4.6.bin__hadoop-2.0.4-alpha/lib/
5.sqoop命令
5.1将hive数据导入mysql
注:
1.先在mysql中建表
2.mysql要授权给yarn子节点
sqoop export --connect jdbc:mysql://linux1:3306/hive --username root --password oracle --table uv --export-dir /root/app/hadoop/hive/warehouse/hive.db/uv/000000_0 --input-fields-terminated-by ' '
5.2从mysql导出数据到hdfs
sqoop import –connect jdbc:mysql://linux1:3306/compression –username=hadoop –password=123456 –table uv -m 1
–target-dir /user/test
5.3从mysql增量导入表数据到hdfs
sqoop import –connect jdbc:mysql://linux1:3306/compression –username=hadoop –password=123456 –table HADOOP_USER_INFO -m 1 –target-dir /user/test –check-column id –incremental append –last-value 3