Fork me on GitHub

hive之路4-CLI和Beeline

Hive之CLI

参数

CLI,command line interface,最常用的命令行接口。

常用参数

参数 说明
-d,—define <key=value> 指定参数
—database 数据库名称
-e 指定查询的字符串,比如select语句
-f 指定文件
-H, -help 显示帮助
-h 主机名
—hiveconf 类似-d效果
-hivevar 定义变量
-i 进入shell之前,先执行指定的文件
-p 指定远程连接的端口
-S,—silent 静默模式,很多内容忽略
-v,—verbose 显示更多的内容

三种配置方式

  1. Hive-site.xml
  2. —hiveconf
  3. hive CLI 中进行set property=value

操作demo

  • -d
1
2
3
4
5
hive -d col=id --database hello   # 指定变量和数据库名称hello

# 使用变量
hive> select '${col}' from table2 limit 3; # 显示的是id名称
hive> select ${col} from table2 limit 3; # 显示的是id的具体值
  • hiveconf
1
2
3
root: hive --hiveconf mapred.reduce.tasks=10

hive> set mapred.map.tasks=10;
  • -e
1
hive -e "select * from table2 where id > 4" --database hello;

Hive之Beeline

beeline简介

beelinehiveserver2CLI,一个JDBC的客户端,分为两种模式

  • 嵌入模式:一个嵌入的Hive
  • 远程模式:通过thrift协议与单独的HiveServer2进程

beeline必须同时和hiveserver2同时使用

使用方法

  1. 启动hiveserver2
  2. 查看是否启动:ps -ef | grep hive
  3. 启动beeline
  4. 退出beeline:!quit
  5. 连接数据库,一定要带上感叹号❕
1
!connect jdbc:hive2://localhost:10000/defautl
6. 直接进入数据库中
1
$ $HIVE_HOME/bin/beeline -u jdbc:hive2://$HS2_HOST:$HS2_PORT

连接报错

  1. 先关闭Hadoop集群
1
/Users/peter/Downloads/hadoop-2.9.2/sbin/stop-all.sh
  1. 通过报错显示,是权限问题:用户不具备权限
1
Error: Could not open client transport with JDBC Uri: jdbc:hive2://localhost:10000/default: Failed to open new session: java.lang.RuntimeException: org.apache.hadoop.ipc.RemoteException(org.apache.hadoop.security.authorize.AuthorizationException): User: piqianchao is not allowed to impersonate root (state=08S01,code=0)
  1. 编辑Hadoop的配置文件,添加两项内容

需要注意的是:将用户进行更改,不一定是root用户

1
vim /Users/peter/Downloads/hadoop-2.9.2/etc/hadoop/core-site.xml

MoZKHO.png

  1. 重启Hadoop集群
1
/Users/peter/Downloads/hadoop-2.9.2/sbin/start-all.sh
  1. 重启hiveserver2

重启hiveserver2beeline,即可正常进入

本文标题:hive之路4-CLI和Beeline

发布时间:2019年11月21日 - 23:11

原始链接:http://www.renpeter.cn/2019/11/21/hive%E4%B9%8B%E8%B7%AF4-CLI%E5%92%8CBeeline.html

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。

Coffee or Tea