目录
3.3.1下载commons-lang-2.6-bin.tar.gz
3.3.2将mysql-connector-j-8.3.0.jar上传到sqoop的lib目录
1.安装jdk
1.1上传jdk安装包到/opt目录下并解压
1.2解压
解压示例
cd /opt
tar -zxvf jdk-8u381-linux-x64.tar.gz
1.3配置环境变量
JAVA_HOME=/opt/jdk1.8.0_381
CLASSPATH=.:$JAVA_HOME/lib.tools.jar
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME CLASSPATH PATH
2.安装hadoop
2.1.下载hadoop
csdn资源审核一直审核中,有道需要登录,可以从互联网找下hadoop资源
cd /opt
wget https://note.youdao.com/s/F3hrTVve
2.2.解压hadoop
tar -xvf hadoop-2.8.5.tar.gz
2.3配置环境变量
vim /etc/profile
增加如下内容
export HADOOP_COMMON_HOME=/opt/hadoop-2.8.5
export PATH=$HADOOP_COMMON_HOME/bin:$PATH
export HADOOP_MAPRED_HOME=/opt/hadoop-2.8.5
export PATH=$HADOOP_MAPRED_HOME/bin:$PATH
使环境生效
source /etc/profile
3.安装sqoop
3.1下载
cd /opt
wget https://archive.apache.org/dist/sqoop/1.4.7/sqoop-1.4.7.bin__hadoop-2.6.0.tar.gz
3.2解压
cd /opt
tar -xvf sqoop-1.4.7.bin__hadoop-2.6.0.tar.gz
3.3下载依赖包并复制到指定位置
3.3.1下载commons-lang-2.6-bin.tar.gz
cd /opt
wget https://mirrors.tuna.tsinghua.edu.cn/apache/commons/lang/binaries/commons-lang-2.6-bin.tar.gz
解压后得到文件commons-lang-2.6.jar
tar -zxvf commons-lang-2.6-bin.tar.gz
将文件commons-lang-2.6.jar复制到sqoop的lib目录
cp /opt/commons-lang-2.6-bin/commons-lang-2.6/commons-lang-2.6.jar /opt/sqoop/lib
3.3.2将mysql-connector-j-8.3.0.jar上传到sqoop的lib目录
由于本地有mysql-connector-j-8.3.0.jar直接上传该jar到sqoop的lib目录
处理完示例
3.4配置环境
vim /etc/profile
增加如下内容
export SQOOP_HOME=/opt/sqoop
export CLASSPATH=$CLASSPASS:$SQOOP_HOME/lib
export PATH=$SQOOP_HOME/bin:$PATH
使环境生效
source /etc/profile
4.使用
4.1导出mysql数据到hadoop
将数据库mysql://192.168.168.76:3306/test表kq_check_detail 的数据导出到/opt/test2
注意:/opt/test2 必须不存在
sqoop import \
--connect jdbc:mysql://192.168.168.76:3306/test \
--username test \
--password 123456 \
--target-dir /opt/test2 \
--query 'SELECT * FROM kq_check_detail WHERE id!=5 AND $CONDITIONS' \
--num-mappers 1 \
--bindir /opt/sqoop/lib
4.2将hadoop数据导入到mysql
/opt/test2导入到数据库mysql://192.168.168.76:3306/test2的表kq_check_detail 中
sqoop export \
--connect jdbc:mysql://192.168.168.76:3306/test2 \
--driver com.mysql.jdbc.Driver \
--username test \
--password 123456 \
--table kq_check_detail \
--export-dir /opt/test2 \
-m 1
4.3创建任务
sqoop job \
--create test\
-- import \
--connect jdbc:mysql://192.168.168.76:3306/test \
--table kq_check_detail \
--username root \
--password 123456 \
--incremental append \
--check-column update_time \
--last-value '2024-07-10 00:00:00' \
--target-dir /data/test/kq_check_detail \
--m 3
4.4执行任务
sqoop job --exec test
4.5删除任务
sqoop job \
--delete test \
-- import \
--connect jdbc:mysql://192.168.168.76:3306/test \
--table kq_check_detail \
--username test \
--password 123456\
--incremental append \
--check-column update_time \
--last-value '2024-07-10 00:00:00' \
--target-dir /data/test/kq_check_detail \
--m 3