HiveServer2是经常与beeline一起使用,可以用jdbc客户端远程连接,一般用于生产环境。

在提供传统客服端的功能之外,还提供其他功能。

Beeline连接

1.先在hadoop集群启动HiveServer2

启动命令:hiveserver2

启动日志在hive.log中查看

2.再启动Beeline

命令: beeline

3.连接

!connect jdbc:hive2://localhost:10000

Beeline命令

传统命令与Beeline命令示例比较:

1.传统:   quit;

2.Beeline:   !quit

SQL语句操作还是和传统一样

HiveServer2 web界面管理

除了在HiveServer2服务端可以看到日志,还可以在hive -site.xml中配置 ip端口后,可提供ui界面

<property>
<name>hive.server2.webui.host</name>
<value>localhost</value>
</property>
<property>
<name>hive.server2.webui.port</name>
<value>10002</value>
</property>

JDBC连接

导入hive依赖包,hadoop-common及其相关依赖

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement; public class HiveServerBeeline {
// 驱动全名
private static String driverName = "org.apache.hive.jdbc.HiveDriver"; public static void main(String[] args) throws SQLException {
// TODO Auto-generated method stub
try {
// JVM查找并加载指定的类,也就是说JVM会执行该类的静态代码段 和 new 示例化对象类似
Class.forName(driverName);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.exit(1);
}
// 连接并登陆数据库
Connection con = DriverManager.getConnection("jdbc:hive2://192.192.192.192:10000/default", "user", "passwd");
// 创建Statement对象
Statement stmt = con.createStatement();
String sql = "show databases";
// stmt.execute("create external table if not exists testdb.test(id int,name String)");
ResultSet res = stmt.executeQuery(sql);     if (res.next()) {
System.out.println(res.getString(1));
}
}

没导入hadoop-common依赖会报异常:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/conf/Configuration
at org.apache.hive.jdbc.HiveConnection.createUnderlyingTransport(HiveConnection.java:418)
at org.apache.hive.jdbc.HiveConnection.createBinaryTransport(HiveConnection.java:438)
at org.apache.hive.jdbc.HiveConnection.openTransport(HiveConnection.java:225)
at org.apache.hive.jdbc.HiveConnection.<init>(HiveConnection.java:182)
at org.apache.hive.jdbc.HiveDriver.connect(HiveDriver.java:107)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at hiveservertwo.HiveServerBeeline.main(HiveServerBeeline.java:32)
Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.conf.Configuration
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 8 more

hive Beeline plus HiveServer2简单使用的更多相关文章

  1. 由“Beeline连接HiveServer2后如何使用指定的队列(Yarn)运行Hive SQL语句”引发的一系列思考

    背景   我们使用的HiveServer2的版本为0.13.1-cdh5.3.2,目前的任务使用Hive SQL构建,分为两种类型:手动任务(临时分析需求).调度任务(常规分析需求),两者均通过我们的 ...

  2. Hive中的HiveServer2、Beeline及数据的压缩和存储

    1.使用HiveServer2及Beeline HiveServer2的作用:将hive变成一种server服务对外开放,多个客户端可以连接. 启动namenode.datanode.resource ...

  3. Hive 教程(八)-hiveserver2

    hive 的另外一种启动方式是 hiveserver2,它是提供了一种服务,使得我们可以远程操作 hive,就像操作 mysql 一样 hiveserver1 既然有 hiveserver2,肯定有 ...

  4. Hive On Spark hiveserver2方式使用

    启动hiveserver2: hiveserver2 --hiveconf hive.execution.engine=spark spark.master=yarn 使用beeline连接hives ...

  5. Hive基础之HiveServer2 JDBC的使用

    启动HiveServer2: cd $HIVE_HOME/bin 以后台方式默认端口启动HiveServer2(默认端口是10000):hiveserver2 & 以后台方式指定端口的方式启动 ...

  6. Hive Beeline 官方文档学习

    Beeline 是什么? 它是一个命令行形式的jdbc客户端.搞Java开发的同学,看到这里就应该知道这货是什么了 ── 它是一个连接数据库的工具. 只不过Beeline连接的数据库是HiveServ ...

  7. hive beeline详解

    Hive客户端工具后续将使用Beeline 替代HiveCLI ,并且后续版本也会废弃掉HiveCLI 客户端工具,Beeline是 Hive 0.11版本引入的新命令行客户端工具,它是基于SQLLi ...

  8. Hive Beeline 命令行参数

    [hadoop@hive ~]$ beeline --help[中文版] The Beeline CLI 支持以下命令行参数: Option Description --autoCommit=[tru ...

  9. 【原创】大叔经验分享(38)beeline连接hiveserver2报错impersonate

    beeline连接hiveserver2报错 Error: Could not open client transport with JDBC Uri: jdbc:hive2://localhost: ...

随机推荐

  1. 通信技术:SSE设计方案(一)--- 前端Server-Sent Events概念讲解和基础类库完善发布

    好了,开篇还是要扯扯的,否则感觉这个技术讲的么有那么冻人,嗯,这个晚上是有点冷了,秋衣秋裤大家都该加起来了,反正我不帮你买,妹子除外,嘻嘻. 之前几篇博客,研究前端通信技术的第一层ajax技术,从最基 ...

  2. 【原创】自用css reset

    自己工作中常用的reset,和一些设置,实际用时会根据网站页面进行增删. /* Common style */html{ overflow-y:scroll; overflow-x:auto;}bod ...

  3. Mvc 流程调用分析

    链接地址 https://www.processon.com/view/link/59e71fbbe4b09000f03ce78e 总结: 1. 在Global.ascx 中我们使用RouteColl ...

  4. 从零开始搭建框架SSM+Redis+Mysql(一)之摘要

    从零开始搭建框架SSM+Redis+Mysql(一)之摘要 本文章为本人实际的操作后的回忆笔记,如果有步骤错漏,希望来信307793969@qq.com或者评论指出. 本文章只体现过程,仅体现操作流程 ...

  5. 通过 PackageManager 获得你想要的 App 信息

    一.前言 开门见山,开篇明义.有些场景下,我们会需要获取一些其它 App 的各项信息,例如:App 名称,包名.Icon 等.这个时候就需要使用到 PackageManager 这个类了. 本篇就 P ...

  6. gcd,最大公约数,lcm,最小公倍数

    int gcd(int a,int b){ ?a:gcd(b,a%b); } 关于lcm,若写成a*b/gcd(a,b) ,a*b可能会溢出! int lcm(int a,int b){ return ...

  7. LINUX 笔记-iostat命令

    显示CPU和I/O统计信息 iostat的不带参数的显示CPU和I/ O的所有分区的统计信息 -c Display the CPU utilization report. -d Display the ...

  8. LeetCode 543. Diameter of Binary Tree (二叉树的直径)

    Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a b ...

  9. [译]ASP.NET Core 2.0 路由引擎之网址生成

    问题 如何在ASP.NET Core 2.0中由路由引擎来生成网址? 答案 新建一个空项目,修改Startup.cs文件,添加MVC服务和中间件: public void ConfigureServi ...

  10. Linux系列教程(十)——Linux文本编辑器vim

    通过前面几篇博客我们终于结束了Linux常用命令的介绍,Linux常用命令主要包括以下: ①.Linux文件和目录处理命令 ②.Linux链接命令和权限管理命令 ③.Linux文件搜索命令 ④.Lin ...