sqoop的使用之导入到hive和mysql

先登录hive

sqoop的使用之导入到hive和mysql

 

在hive中操作,创建数据库:

create database frommysql;

sqoop的使用之导入到hive和mysql

 

创建表

创建表

create table importhive_info(

num int,

name string

)row format delimited fields terminated by "\t";

sqoop的使用之导入到hive和mysql

 

数据也有了

sqoop的使用之导入到hive和mysql

 

执行语句

bin/sqoop import \

--connect jdbc:mysql://mastercdh:3306/sqoop_test \

--username root \

--password password \

--direct \

--table importhdfs \

--delete-target-dir \

--hive-import \

--hive-database frommysql \

--hive-table importhive_info \

--fields-terminated-by "\t" \

-m 1

执行报错

sqoop的使用之导入到hive和mysql

 

但是我们数据库明明有

查看mysql元数据信息发现新建的库表都没有

sqoop的使用之导入到hive和mysql

 

难道没有使用mysql的元数据库?初始化出问题了吗?于是重新初始化

bin/schematool -dbType mysql –initSchema

出现derby信息,还是旧信息

sqoop的使用之导入到hive和mysql

 

我的配置没有起作用?

sqoop的使用之导入到hive和mysql

 

为什么会有元数据库呢?说明之前是对的,仔细核对了一遍,发现是配置文件被我改动的问题。

这个地方写错路径了(截图已改对)

sqoop的使用之导入到hive和mysql

 

重新启动

sqoop的使用之导入到hive和mysql

 

Mysql中元数据库有了

sqoop的使用之导入到hive和mysql

 

重新创建上面的库表

sqoop的使用之导入到hive和mysql

 

sqoop的使用之导入到hive和mysql

 

元数据有信息了

sqoop的使用之导入到hive和mysql

 

在执行之前的sqoop语句

sqoop的使用之导入到hive和mysql

 

查看下hive中的数据已经有了

sqoop的使用之导入到hive和mysql

 

这个地方注意:运行mr任务时,结果将会保存在默认的输出目录上。还在/user/hive/warehouse。

sqoop的使用之导入到hive和mysql

 

从hdfs导入到mysql(export)

常规模式导入数据到mysql

我们创建一个表

create table tomysql(

id int primary key not null,

name varchar(20) not null

);

sqoop的使用之导入到hive和mysql

 

导出语句

bin/sqoop export \

--connect jdbc:mysql://mastercdh:3306/sqoop_test \

--username root \

--password password \

--table tomysql \

--export-dir /user/hive/warehouse/frommysql.db/importhive_info \

-m 1 \

--input-fields-terminated-by '\t'

sqoop的使用之导入到hive和mysql

 

查看下数据

sqoop的使用之导入到hive和mysql

 

sqoop运行一个file文件

在mysql重新建表file_to_mysql

sqoop的使用之导入到hive和mysql

 

创建文本

export

--connect

jdbc:mysql://mastercdh:3306/sqoop_test

--username

root

--password

password

--table

file_to_mysql

--export-dir

/user/hive/warehouse/frommysql.db/importhive_info

-m

1

--input-fields-terminated-by

'\t'

sqoop的使用之导入到hive和mysql

 

执行命令

bin/sqoop --options-file /data/test/filetomysql

sqoop的使用之导入到hive和mysql

 

查看数据已经有了

sqoop的使用之导入到hive和mysql

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值