题目:
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
标签:02,nbr,sale,hive,id,text3,HIVE,day From: https://www.cnblogs.com/jzz-111jy/p/16768292.html