我是靠谱客的博主 丰富洋葱,这篇文章主要介绍hive mysql 同步_hive数据同步(sqoop :Mysql ==>Hive,hive put 文件到hive),现在分享给大家,希望可以做个参考。

一、Sqoop同步mysql数据到hive:

假设我们在Hive里新建了一张测试表info_test,该表对应mysql 数据库中info_test:CREATE TABLE info_test(id BIGINT,uid INT, name STRING, tel STRING, )

row format delimited

fields terminated by '~' ;

我们以‘~’分割字符,同时,注意,两张表的字段以及顺序必须一致。

接着,开始利用sqoop同步数据:sqoop import --connect jdbc:mysql://你的mysql数据库地址/数据库表名(如info_test)?zeroDateTimeBehavior=convertToNull --username (账户) --password (密码) --table mysql数据库表名(如info_test) --hive-table db名+表名(如info.info_test ) --hive-import --delete-target-dir -m 1 --hive-overwrite --fields-terminated-by "~"

解释一下几个参数:

1、overwrite:覆写

2、--fields-terminated-by "~" :指定该命令是对应建表时的那个‘fields terminated by '~' ;’表示以此分割

二、通过put文件到Hive中同步数据:清空表:/data/dps-hadoop/hadoop-2.6.4/bin/hadoop fs -rm /user/hive/warehouse/r****.db/spider_buying_test/*

PUT数据:/data/dps-hadoop/hadoop-2.6.4/bin/hadoop fs -put ./SettingBuying.txt /user/hive/warehouse/****.db/spider_buying_test/

最后

以上就是丰富洋葱最近收集整理的关于hive mysql 同步_hive数据同步(sqoop :Mysql ==>Hive,hive put 文件到hive)的全部内容,更多相关hive内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(89)

评论列表共有 0 条评论

立即
投稿
返回
顶部