sqoop--mysql表导入hive

mysql 导入 hive
如果使用之前的方式
需要3个步骤:
1、mysql -> HDFS
2、创建hive表
3、将数据load到hive表中
如果可以直接把mysql的数据导入hive中进行分析,会相当的方便
bin/sqoop import \
--connect jdbc:mysql://[hostname]:3306/sqoop \
--username root \
--password 123456 \
--table tohdfs \
--direct \
--delete-target-dir \
--hive-import \
--hive-database student \
--hive-table stu_info2 \
--num-mappers 1 \

--fields-terminated-by '\t'


在hive里操作:
create database student;


create table stu_info(
id int,
name string
)row format delimited fields terminated by '\t';


机制:运行MR任务时,结果会在默认输出目录生成,然后将结果集文件移动到hive对应的表文件夹下面


-----------------------------------------------------------------------------------------------
报错1:
Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.hive.conf.HiveConf
解决办法:
在 hadoop-env.sh : export HADOOP_CLASSPATH=$HADOOP_CLASSPATH:$HIVE_HOME/lib/*

报错:
FAILED: SemanticException [Error 10072]: Database does not exist: XXX
原因:当没有在sqoop的conf目录下找到hive-site.xml时,sqoop默认采用的是读取deby内置的数据库
解决办法:将hive-site.xml 放到sqoop的conf目录下


-----------------------------------------------------------------------------------------------

猜你喜欢

转载自blog.csdn.net/qq_33187206/article/details/80620535