将Hive统计分析结果导入到MySQL数据库表中(二)——使用Hive和MySQL JDBC驱动

        上一篇文章中,我介绍了一种将Hive分析结果,通过存放到另外一个Hive表中,使用Sqoop将该表内容直接导入到MySQL中的方法。本人认为这种方式在数据量特别大的时候,可能很有效果,但是一般情况下,Hive的分析、查询、统计结果数据量不会太大,所以在这种情况下,我尝试使用Hive JDBC驱动连接Hive将查询结果集,通过MySQL JDBC驱动,直接导入到数据库中,并取得成功,速度也比Sqoop方式快了很多。

一、启动Hive元数据服务

[hadoopUser@secondmgt ~]$ hive --service metastore
 Starting Hive Metastore Server
15/04/22 14:53:12 INFO Configuration.deprecation: mapred.reduce.tasks is deprecated. Instead, use mapreduce.job.reduces
15/04/22 14:53:12 INFO Configuration.deprecation: mapred.min.split.size is deprecated. Instead, use mapreduce.input.fileinputformat.split.minsize
15/04/22 14:53:12 INFO Configuration.deprecation: mapred.reduce.tasks.speculative.execution is deprecated. Instead, use mapreduce.reduce.speculative
15/04/22 14:53:12 INFO Configuration.deprecation: mapred.min.split.size.per.node is deprecated. Instead, use mapreduce.input.fileinputformat.split.minsize.per.node
15/04/22 14:53:12 INFO Configuration.deprecation: mapred.input.dir.recursive is deprecated. Instead, use mapreduce.input.fileinputformat.input.dir.recursive
15/04/22 14:53:12 INFO Configuration.deprecation: mapred.min.split.size.per.rack is deprecated. Instead, use mapreduce.input.fileinputformat.split.minsize.per.rack
15/04/22 14:53:12 INFO Configuration.deprecation: mapred.max.split.size is deprecated. Instead, use mapreduce.input.fileinputformat.split.maxsize
15/04/22 14:53:12 INFO Configuration.deprecation: mapred.committer.job.setup.cleanup.needed is deprecated. Instead, use mapreduce.job.committer.setup.cleanup.needed
二、启动HiveServer2服务

[hadoopUser@secondmgt ~]$ hive --service hiveserver2
Starting HiveServer2
15/04/22 14:58:22 INFO Configuration.deprecation: mapred.reduce.tasks is deprecated. Instead, use mapreduce.job.reduces
15/04/22 14:58:22 INFO Configuration.deprecation: mapred.min.split.size is deprecated. Instead, use mapreduce.input.fileinputformat.split.minsize
15/04/22 14:58:22 INFO Configuration.deprecation: mapred.reduce.tasks.speculative.execution is deprecated. Instead, use mapreduce.reduce.speculative
15/04/22 14:58:22 INFO Configuration.deprecation: mapred.min.split.size.per.node is deprecated. Instead, use mapreduce.input.fileinputformat.split.minsize.per.node
15/04/22 14:58:22 INFO Configuration.deprecation: mapred.input.dir.recursive is deprecated. Instead, use mapreduce.input.fileinputformat.input.dir.recursive
15/04/22 14:58:22 INFO Configuration.deprecation: mapred.min.split.size.per.rack is deprecated. Instead, use mapreduce.input.fileinputformat.split.minsize.per.rack
15/04/22 14:58:22 INFO Configuration.deprecation: mapred.max.split.size is deprecated. Instead, use mapreduce.input.fileinputformat.split.maxsize
15/04/22 14:58:22 INFO Configuration.deprecation: mapred.committer.job.setup.cleanup.needed is deprecated. Instead, use mapreduce.job.committer.setup.cleanup.needed
三、Hive关联HBase数据库表

        部分数据查询,结果如下,HBase中目前存放有6649条数据

hive> select  * from transjtxx_hbase;
32108800000000004620140317000817    02   03      苏K22F91        0.00    3       1       0       0
32108800000000004620140317000820    02   03      苏HP062H        0.00    6       1       0       0
32108800000000004620140317000823    02   03 
  • 1
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
可以使用Sqoop工具将MySQL中mydb数据库中表news的数据导入Hive数据库mydb中news表中。以下是具体步骤: 1. 确保Sqoop已经正确安装和配置,并且Hive的元数据存储在MySQL中。 2. 在Hive中创建一个与MySQL表对应的Hive表。可以使用以下命令: ``` CREATE TABLE mydb.news ( id INT, title STRING, content STRING, publish_time TIMESTAMP ) STORED AS PARQUET; ``` 这将在Hive中创建一个新的Parquet格式的表,用于存储MySQL表中数据。 3. 使用Sqoop将MySQL中的数据导入Hive中。可以使用以下命令: ``` sqoop import \ --connect jdbc:mysql://mysql_host/mydb \ --username mysql_user \ --password mysql_password \ --table news \ --hive-import \ --hive-table mydb.news \ --incremental append \ --check-column id \ --last-value 0 \ --split-by id \ --target-dir /tmp/news ``` 其中,`--connect`参数指定MySQL数据库连接信息,`--username`和`--password`指定MySQL数据库的用户名和密码,`--table`参数指定要导入MySQL表名,`--hive-import`参数表示将数据导入Hive中,`--hive-table`参数指定要导入到的Hive表名,`--incremental`参数表示增量导入数据,`--check-column`参数指定用于增量导入的列名,`--last-value`参数指定增量导入的起始值,`--split-by`参数指定用于拆分任务的列名,`--target-dir`参数指定导入数据的目录。 4. 最后,使用以下命令在Hive中查看导入数据: ``` SELECT * FROM mydb.news; ``` 这将显示导入Hive表中数据

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值