HiveServer2是一个能使客户端针对hive执行查询的一种服务,与HiverServer1比较,它能够支持多个客户端的并发请求和授权的;HiveCLI 和 hive –e的方式比较单一,HS2允许远程客户端使用多种语言诸如Java,Python等向Hive提交请求,然后取回结果.

$HIVE_HOME/bin目录下面的hiveserver2

由于配置了环境变量因此可以直接使用

nohup hiveserver2 1>/hiveserver2log/log.txt 2>/hiveserver2log/log.err &

命令中的 1 和 2 的意义分别是:

1:表示标准日志输出

2:表示错误日志输出 如果我没有配置日志的输出路径,日志会生成在当前工作目录,默认的日志名称叫做: nohup.xxx

作为数据仓库的工具,hive提供了两种ETL运行方式,分别是通过Hive 命令行和beeline客户端;

命令行方式即通过hive进入命令模式后通过执行不同的HQL命令得到对应的结果;相当于胖客户端模式,即客户机中需要安装JRE环境和Hive程序。

beeline客户端方式相当于瘦客户端模式,采用JDBC方式借助于Hive Thrift服务访问Hive数据仓库。

$HIVE_HOME/bin目录下面的beeline

由于配置了环境变量因此可以直接使用,使用过程中要指定hive的链接信息,用户名,密码

测试环境无密码

[root@host ~]# beeline
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/root/hive/apache-hive-2.1.1/lib/log4j-slf4j-impl-2.4.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/root/spark/spark-2.2.0-bin-hadoop2.7/jars/slf4j-log4j12-1.7.16.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/root/hadoop/hadoop-2.7.4/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
Beeline version 2.1.1 by Apache Hive
beeline>  !connect jdbc:hive2://192.168.53.122:10000/default
Connecting to jdbc:hive2://192.168.53.122:10000/default
Enter username for jdbc:hive2://192.168.53.122:10000/default: root
Enter password for jdbc:hive2://192.168.53.122:10000/default:
Connected to: Apache Hive (version 2.1.1)
Driver: Hive JDBC (version 2.1.1)
18/09/06 16:08:26 [main]: WARN jdbc.HiveConnection: Request to set autoCommit to false; Hive does not support autoCommit=false.
Transaction isolation: TRANSACTION_REPEATABLE_READ
0: jdbc:hive2://192.168.53.122:10000/default> show databases;
+----------------+--+
| database_name  |
+----------------+--+
| default        |
| gamedw         |
| hive_hbase     |
| sqoopdb        |
| testdb         |
| userdb         |
+----------------+--+
6 rows selected (0.335 seconds)
0: jdbc:hive2://192.168.53.122:10000/default>

也可以用下面方式:

[root@host ~]# beeline -u jdbc:hive2://192.168.53.122:10000/default -n root
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/root/hive/apache-hive-2.1.1/lib/log4j-slf4j-impl-2.4.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/root/spark/spark-2.2.0-bin-hadoop2.7/jars/slf4j-log4j12-1.7.16.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/root/hadoop/hadoop-2.7.4/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
Connecting to jdbc:hive2://192.168.53.122:10000/default
Connected to: Apache Hive (version 2.1.1)
Driver: Hive JDBC (version 2.1.1)
18/09/06 16:16:38 [main]: WARN jdbc.HiveConnection: Request to set autoCommit to false; Hive does not support autoCommit=false.
Transaction isolation: TRANSACTION_REPEATABLE_READ
Beeline version 2.1.1 by Apache Hive
0: jdbc:hive2://192.168.53.122:10000/default> show databases;
+----------------+--+
| database_name  |
+----------------+--+
| default        |
| gamedw         |
| hive_hbase     |
| sqoopdb        |
| testdb         |
| userdb         |
+----------------+--+
6 rows selected (0.178 seconds)
0: jdbc:hive2://192.168.53.122:10000/default>

可以直接通过-u -n-p -e等参数让其执行我们的操作,参数选项:

-u<database URL> 要连接的数据库的URL

-n<username> 指定要连接数据库的用户名

-p<password> 指定要连接数据库的密码

-d<driver class> 使用的驱动名字

-i<init file> 初始化的脚本文件

-e<query> 要执行的查询

-f<exec file> 要执行的脚本文件

-w/--password-file<password file> 从文件读取密码

--hiveconf<key=value> 指定hive配置文件

--hivevarname=value 设置hive变量

--showHeader=[true/false]控制是否在查询结果显示列名

--autoCommit=[true/false]是否自动提交事务

--force=[true/false]运行脚本出错是否继续

--outputformat=[table/vertical/csv2/tsv2/dsv]  指定结果展示的格式

beeline 连接hive的更多相关文章

  1. beeline连接hive server遭遇MapRedTask (state=08S01,code=1)错误

    采用beeline连接hive server是遭遇到如下错误: 5: jdbc:hive2://bluejoe0/default> select * from hive_triples wher ...

  2. 使用 beeline 连接 hive 数据库报错处理

    一.beeline连接hive报错 1. User: root is not allowed to impersonate root (state=08S01,code=0) 在初次搭建完hadoop ...

  3. 设置beeline连接hive的数据展示格式

    问题描述:beeline -u 方式导出数据,结果文件中含有"|"(竖杠). 执行的sql为:beeline -u jdbc:hive2://hadoop1:10000/defau ...

  4. beeline连接hive

    beeline -u jdbc:hive2://192.168.1.77:10000 zeppelin default jdbc: jdbc:hive2://nn01.ooccpp.com:2181/ ...

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

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

  6. sparkSQL元数据缓存不同步 beeline连接的表结构与hive不一致

    之前遇到过的坑,通过beeline连接spark thirft server,当在Hive进行表结构修改,如replace/add/change columns后,表结构没有变化,还是旧的表结构,导致 ...

  7. java使用JDBC连接hive(使用beeline与hiveserver2)

    首先虚拟机上已经安装好hive. 下面是连接hive需要的操作. 一.配置. 1.查找虚拟机的ip 输入 ifconfig 2.配置文件 (1)配置hadoop目录下的core-site.xml和hd ...

  8. Hive 8、Hive2 beeline 和 Hive jdbc

    1.Hive2 beeline  Beeline 要与HiveServer2配合使用,支持嵌入模式和远程模式 启动beeline 打开两个Shell窗口,一个启动Hive2 一个beeline连接hi ...

  9. 【原创】大叔问题定位分享(18)beeline连接spark thrift有时会卡住

    spark 2.1.1 beeline连接spark thrift之后,执行use database有时会卡住,而use database 在server端对应的是 setCurrentDatabas ...

随机推荐

  1. IDEA创建Springmvc项目

    项目主要步骤如下: 1.创建一个javaweb动态项目 2.导入springmvc demo所需要的jar包 3.生成项目war包 4.配置项目tomacat服务器 5.配置web.xml文件 6.编 ...

  2. ALGO-123_蓝桥杯_算法训练_A+B problem

    问题描述 Given two integers A and B, your task is to output their sum, A+B. 输入格式 The input contains of o ...

  3. 利用cbmakegen导出Code::blocks的Makefile

    首先到官网下载cbmakegen 官网地址:http://developer.berlios.de/projects/cbmakegen/ 也可通过我的百度网盘下载 [windows版本]地址:htt ...

  4. Socket调用Close后如何终止套接口的问题

    setsockopt 设置 SO_LINGER 选项 此选项指定函数close对面向连接的协议如何操作(如TCP).内核缺省close操作是立即返回,如果有数据残留在套接口缓冲区中则系统将试着将这些数 ...

  5. spring笔记-@Primary注解

    1.问题 当一个接口有2个不同实现时,使用@Autowired注解时会报org.springframework.beans.factory.NoUniqueBeanDefinitionExceptio ...

  6. JAVA Map 和 List 排序方法

    private Map<String,String> mapDate; //正序 mapDate=new TreeMap<String, String>(new Compara ...

  7. Activity的启动模式--总结

    3. Activity的任务栈Task以及启动模式与Intent的Flag详解? 2,Activity次级页面和主页间来回跳转,防止重复创建Activity实例 1, activity的启动模式: / ...

  8. psql: could not connect to server: No such file or directory&&PGHOST

    由于环境变量 PGHOST配置不当引起的 postgres@pgdb-> psql psql: could not connect to server: No such file or dire ...

  9. tensorFlow 三种启动图的用法

    tf.Session(),tf.InteractivesSession(),tf.train.Supervisor().managed_session()  用法的区别: tf.Session() 构 ...

  10. SQL SERVER 事务相关

    1 准备数据 及 涉及到的几个设置 SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED  --设置事务会话的隔离等级(默认值为 READ UNCOMMIT ...