您的位置:首页 > 大数据

大数据(二十三)Hive【Hive三种启动方式 、 HIVE Server2详解 、 jdbc链接HIVE】

2017-10-29 14:04 921 查看

一:Hive的三种启动方式

1, hive  命令行模式

        进入hive安装目录,输入bin/hive的执行程序,或者输入 hive –service cli        用于linux平台命令行查询,查询语句基本跟mysql查询语句类似

 2, hive  web界面的启动方式

        bin/hive –service hwi  (& 表示后台运行)        用于通过浏览器来访问hive,感觉没多大用途,浏览器访问地址是:127.0.0.1:9999/hwi

 3, hive  远程服务 (端口号10000) 启动方式

        bin/hive –service hiveserver2  &(&表示后台运行)        用java,python等程序实现通过jdbc等驱动的访问hive就用这种起动方式了,这个是程序员最需要的方式了

二:HiveServer2

1, 启动命令

       
hive --service hiveserver   /   
hiveserver2

2, 启动结果验证

       
telnet localhost 10000

3, 命令行链接hiveserver2

 
     
[root@node5 ~]# beeline
       
Beelineversion 1.2.1 by Apache Hive
       
beeline>!connect jdbc:hive2://localhost:10000 root
       
Connectingto jdbc:hive2://localhost:10000
       
Enterpassword for jdbc:hive2://localhost:10000:
       
Connectedto: Apache Hive (version 1.2.1)
       
Driver:Hive JDBC (version 1.2.1)
       
Transactionisolation: TRANSACTION_REPEATABLE_READ
       
0:jdbc:hive2://localhost:10000>
[/code]
 
     
[/code]0: jdbc:hive2://localhost:10000> show tables;
 
     
[/code]+-------------------+--+
 
     
[/code]|     tab_name      |
 
     
[/code]+-------------------+--+
 
     
[/code]| page_view         |
 
     
[/code]| partitioned_test  |
 
     
[/code]| people            |
 
     
[/code]| people_new        |
 
     
[/code]+-------------------+--+
 
     
[/code]4 rows selected (0.066 seconds)

4,JDBC链接HIVE

      
1、在Intellij下新建项目。                          2、在项目中引入需要的hive和hadoop相关jar包                    jar包分别位于hadoop-2.5.1\share\hadoop\commonapache-hive-1.2.1-bin\apache-hive-1.2.1-bin\lib中           3、新建测试类
/*** Created by ZhangJintao on 2017/10/29.*/import java.sql.Connection;import java.sql.ResultSet;import java.sql.Statement;import java.sql.DriverManager;public class testHIVESERVER2 {//驱动 urlprivate static String driverName = "org.apache.hive.jdbc.HiveDriver";/*** @param args*/public static void main(String[] args)  {try {//加载驱动Class.forName(driverName);//链接hive数据仓库Connection con = DriverManager.getConnection("jdbc:hive2://192.168.1.205:10000/default", "root", "");//创建会话Statement stmt = con.createStatement();//执行dql,得到结果集ResultSet res = stmt.executeQuery("select count(*) from people " );// 遍历结果集,打印数据if(res.next()){System.out.println(res.getInt(1));}} catch (Exception e) {// 打印异常e.printStackTrace();System.exit(1);}}}
           4、运行项目                    控制台显示如下,这表示项目已经启动,hadoop正在执行mapreduce。                                       此时我们前往http://192.168.1.201:8088下查看Scheduler和Applications,可以看到这个查询的mapreduce正在执行,如下图所示                                                               待其执行完毕,我们就可以看到程序有如下输出                     

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: