Hive 8、Hive2 beeline 和 Hive jdbc

1、Hive2 beeline 

Beeline 要与HiveServer2配合使用,支持嵌入模式和远程模式

启动beeline

打开两个Shell窗口,一个启动Hive2 一个beeline连接hive2

#启动HiverServer2 , ./bin/hiveserver2
[[email protected] ~]# hiveserver2
16/02/23 22:55:25 WARN conf.HiveConf: HiveConf of name hive.metastore.local does not exist

  

#启动Beeline
# $ ./bin/beeline 下面的方式需要配置Hive的环境变量
[[email protected] ~]# beeline
Beeline version 1.2.1 by Apache Hive
beeline>

  启动beeline之后可以尝试连接hiveserver2

beeline> !connect jdbc:hive2://node5:10000
Connecting to jdbc:hive2://node5:10000
Enter username for jdbc:hive2://node5:10000:
#默认 用户名就是登录账号 密码为空

  2、Hive jdbc

打开Eclipse 新建一个Java 项目:

public class Demo {

    public static void main(String[] args) {
        try {
            Class.forName("org.apache.hive.jdbc.HiveDriver");
            Connection conn = DriverManager.getConnection("jdbc:hive2://node5:10000/hive","root","123456");
            String sql = "select * from news";
            Statement sment = conn.createStatement();
            ResultSet rs = sment.executeQuery(sql);
            while(rs.next()){
                HiveQueryResultSet hqrs = (HiveQueryResultSet)rs;
                System.out.println(hqrs.getString(1)+"\t"+hqrs.getString(2));
            }
            conn.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

  在Hive数据库中有这样一个表 news

hive> use hive
    > ;
OK
Time taken: 4.244 seconds
hive> select * from news;
OK
   I‘m tom
   what are you doing
   i‘m ok
Time taken: 1.247 seconds, Fetched: 3 row(s)

  执行完Java代码以后,可以看到数据正常查询出来了

原文地址:https://www.cnblogs.com/tesla-turing/p/11509313.html

时间: 2024-07-29 00:59:31

Hive 8、Hive2 beeline 和 Hive jdbc的相关文章

Spark SQL 使用beeline访问hive仓库

一.添加hive-site.xml 在$SPARK_HOME/conf下添加hive-site.xml的配置文件,目的是能正常访问hive的元数据 vim hive-site.xml <configuration> <property> <name>javax.jdo.option.ConnectionURL</name> <value>jdbc:mysql://192.168.1.201:3306/hiveDB?createDatabaseIf

Hive 系列(三)—— Hive CLI 和 Beeline 命令行的基本使用

一.Hive CLI 1.1 Help 使用 hive -H 或者 hive --help 命令可以查看所有命令的帮助,显示如下: usage: hive -d,--define <key=value> Variable subsitution to apply to hive commands. e.g. -d A=B or --define A=B --定义用户自定义变量 --database <databasename> Specify the database to use

beeline链接hive报错

看问题:beeline连接hiveserver2报错.连接串:hive  --service beeline -u jdbc:hive2://s1:10000/hive 错误:Error: Could not open client transport with JDBC Uri: jdbc:hive2://s1:10000/hive: Failed to open new session: java.lang.RuntimeException: org.apache.hadoop.ipc.Re

Hive 接口介绍(Web UI/JDBC)

Hive 接口介绍(Web UI/JDBC) 实验简介 本次实验学习 Hive 的两种接口:Web UI 以及 JDBC. 一.实验环境说明 1. 环境登录 无需密码自动登录,系统用户名shiyanlou,密码shiyanlou 2. 环境介绍 本实验环境采用带桌面的Ubuntu Linux环境,实验中会用到桌面上的程序: XfceTerminal: Linux命令行终端,打开后会进入Bash环境,可以使用Linux命令: Firefox:浏览器,可以用在需要前端界面的课程里,只需要打开环境里写

Hive基础(4)---Hive的内置服务

版权声明:<—— 本文为作者呕心沥血打造,若要转载,请注明出处@http://blog.csdn.net/gamer_gyt <—— 目录(?)[+] 一:Hive的几种内置服务 执行bin/hive --service help  如下: [html] view plain copy [[email protected] hive]$ bin/hive --service help ls: 无法访问/opt/spark/lib/spark-assembly-*.jar: 没有那个文件或目录

Hive基础之Hive体系架构&amp;运行模式&amp;Hive与关系型数据的区别

Hive架构 1)用户接口: CLI(hive shell):命令行工具:启动方式:hive 或者 hive --service cli ThriftServer:通过Thrift对外提供服务,默认端口是10000:启动方式:hive --service hiveserver WEBUI(浏览器访问hive):通过浏览器访问hive,默认端口是9999:启动方式:hive --service hwi 2)元数据存储(Metastore):启动方式:hive -service metastore

[[Hive - LanguageManual ] ]SQL Standard Based Hive Authorization

Status of Hive Authorization before Hive 0.13 SQL Standards Based Hive Authorization (New in Hive 0.13) Restrictions on Hive Commands and Statements Privileges Objects Object Ownership Users and Roles Names of Users and Roles Role Management Commands

Hive学习(九)Hive体系结构

1.Hive架构与基本组成 下面是Hive的架构图. 图1.1 Hive体系结构 Hive的体系结构可以分为以下几部分: (1)用户接口主要有三个:CLI,Client 和 WUI.其中最常用的是CLI,Cli启动的时候,会同时启动一个Hive副本.Client是Hive的客户端,用户连接至Hive Server.在启动 Client模式的时候,需要指出Hive Server所在节点,并且在该节点启动Hive Server. WUI是通过浏览器访问Hive. (2)Hive将元数据存储在数据库中

Hive初步使用、安装MySQL 、Hive配置MetaStore、配置Hive日志《二》

一.Hive的简单使用 基本的命令和MySQL的命令差不多 首先在 /opt/datas 下创建数据  students.txt 1001 zhangsan 1002 lisi 1003 wangwu 显示有多少数据库: show databases; 使用某个数据库: use 数据库名称; 显示当前数据库下的表: show tables; 创建数据表 : create table student (id int,name string) ROW FORMAT DELIMITED FIELDS