随笔 - 217  文章 - 4  评论 - 4  阅读 - 23587

hive测试——HIVE数据分析02

题目:

4、处理结果入库:(在虚拟机安装mysql)   

将上述统计分析的结果数据保存到mySQL数据库中。

 

复制代码
#text3_1入库

#1.添加驱动,在hive的lib目录下,如果有则不需要添加

add jar /export/server/hive/lib/hive-contrib-3.1.2.jar

add jar /export/server/hive/lib/mysql-connector-java-5.1.32.jar

#2.创建临时函数,需要在mysql提前创建好表


CREATE TEMPORARY FUNCTION dboutput AS 'org.apache.hadoop.hive.contrib.genericudf.example.GenericUDFDBOutput'


select dboutput('jdbc:mysql://node1:3306/hive3?useSSL=false','root','pwd','INSERT INTO text3_1(day_id, sale_nbr, cnt, round) VALUES (?, ?, ?, ?)',day_id, sale_nbr, cnt, round) from text3_1

 
复制代码

 

 

#text3_2入库
CREATE TEMPORARY FUNCTION dboutput AS 'org.apache.hadoop.hive.contrib.genericudf.example.GenericUDFDBOutput' select dboutput('jdbc:mysql://node1:3306/hive3?useSSL=false','root','pwd','INSERT INTO text3_2(day_id, sale_nbr, cnt, round) VALUES (?, ?, ?, ?)',day_id, sale_nbr, cnt, round) from text3_2

 

 

复制代码
#text3_3入库

CREATE TEMPORARY FUNCTION dboutput AS 'org.apache.hadoop.hive.contrib.genericudf.example.GenericUDFDBOutput'

 

select dboutput('jdbc:mysql://node1:3306/hive3?useSSL=false','root','pwd','INSERT INTO text3_3(day_id, sale_nbr, cnt, round) VALUES (?, ?, ?, ?)',day_id, sale_nbr, cnt, round) from text3_3

复制代码

 

#profit入库
CREATE TEMPORARY FUNCTION dboutput AS 'org.apache.hadoop.hive.contrib.genericudf.example.GenericUDFDBOutput'

select dboutput('jdbc:mysql://node1:3306/hive3?useSSL=false','root','pwd','INSERT INTO profit(day_id,sale_nbr,incnt,inround,outcnt,outround,li) VALUES (?, ?, ?, ?, ?, ?, ?)',day_id, sale_nbr,incnt,inround,outcnt,outround,li) from profit

 profit表入库使用上述方法会很慢,毕竟4900000多条数据,

下面是第二张方法,先导出为.txt文件,在使用mysql可视化工具导入

#导出为.txt,在hive目录下,直接在bin目录下命令不执行

bin/hive -e "select * from dbtest.profit" >> /export/software/profit.txt;

然后将虚拟机的文件传到电脑桌面,直接使用navicat导入,速度非常快。

 

posted on   跨越&尘世  阅读(223)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· DeepSeek在M芯片Mac上本地化部署
历史上的今天:
2021-10-08 Java学习十七
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示