hive准备
创建测试数据
以root用户登录,使用hive命令启动hive。
创建库
create database testhivedb;

创建表
create table testhivedb.testhivetable(
id int
,name string
);

插入数据
insert into testhivedb.testhivetable values (1,'cc');
insert into testhivedb.testhivetable values (2,'yy');
insert into table testhivedb.testhivetable values (1,'cc'),(2,'yy');



验证

配置远程连接
使用远程连接模式,需要配置$HADOOP_HOME/etc/hadoop/core-site.xml中的代理。如果是集群的话,配置后还需要将文件复制到其他节点。

重启hadoop、重启hive。
并且重启hive服务时,要以root用户登录,使用命令 hive --service hiveserver2 启动hive服务。如果是以命令hive启动hive服务,那么只能服务器本地访问hive。

jdbc驱动
直接使用hive驱动包
hive部署完成后,路径$HIVE_HOME/jdbc/hive-jdbc-3.1.3-standalone.jar有有完整的hive的jdbc驱动,直接使用即可。
整合jar包自制驱动包
已知的hive的jdbc驱动,是多个零散的jar包,并没有整合的。突然联想到maven依赖,直接使用maven下载hive-jdbc依赖,然后打包成一个整体。
测试通过
使用idea新建项目,按照如下所示,然后在pom中添加hive-jdbc依赖。

使用maven下载所有依赖

创建java,测试连接hive


验证
整合打包
将App.java全部注释
pom文件中,只保留hive相关内容

并在</dependencies>后添加如下内容

按照下图所示打包

打包后,会生成两个包,
hive-jdbc-1.0-SNAPSHOT-jar-with-dependencies.jar
hive-jdbc-1.0-SNAPSHOT.jar
dbeaver上传驱动时,使用hive-jdbc-1.0-SNAPSHOT-jar-with-dependencies.jar
dbeaver
下载地址:https://dbeaver.io/download/
社区版开源免费,选择这个版本即可。
下载安装

选择自己的版本,本例中选择Mac OS X for Intel(dmg),下载完成后,如下所示,双击安装。


安装完成后,在应用中启动DBeaver.


配置使用hive自带驱动包



上图添加了驱动hive-jdbc-3.1.3-standalone.jar,预置的两个驱动下载url可以直接删除。

点击【确定】,如下所示,连接成功。

配置使用自制驱动包
删除hive自带驱动包,添加自制驱动包文件。


