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导入,速度非常快。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· DeepSeek在M芯片Mac上本地化部署
2021-10-08 Java学习十七