使用脚本加载数据
MySQL有一张表

hive创建一张相同的表

编写脚本同步数据
bash
[root@master sqoop]# vim stu.sh
#!/bin/bash
SQOOP=/usr/local/soft/sqoop-1.4.6/bin/sqoop
$SQOOP import --connect jdbc:mysql://192.168.67.100:3306/sqoop \
--username root \
--password 123456 \
--query "select sid,sname from stu where 1=1 and \$CONDITIONS" \
-m 3 \
--target-dir "/user/hive/warehouse/test.db/stu" \
--split-by sid \
--delete-target-dir \
--fields-terminated-by '\t'
[root@master sqoop]# chmod +x stu.sh
[root@master sqoop]# vim stu.sh
注释;
1)SQOOP路径
2)MySQL地址 端口号 数据库名
3)用户名
4)密码
5)SQL语句
6)hive的表路径(登录Hadoop网页 查看)

7)分隔符

执行成功 查看数据
