Beeline,它其实是HiveServer2的JDBC客户端,基于SQLLine命令行接口。Beeline Shell可以工作在嵌入式模式和远程模式,在嵌入式模式中,它运行一个嵌入式的Hive(类似于Hive CLI),在远程模式中,通过Thrift连接到一个单独的HiveServer2进程,从Hive 0.14开始,当Beeline和HiveServer2一起使用时,它会从HiveServer2打印执行查询的日志信息到STDERR。建议在生产环境使用远程HiveServer2模式,因为这样更安全,不需要为用户授予直接的HDFS/Metastore访问权限。
一 Hive环境
hive> select version();
OK
2.3.3 r8a511e3f79b43d4be41cd231cf5c99e43b248383
Time taken: 11.166 seconds, Fetched: 1 row(s)
二 运行Beeline
Hive的运行依赖于Hadoop,所以首先启动Hadoop,而Beeline的运行必须首先启动HiveServer2,下面将分别介绍:
1 启动HDFS
[hadoop@strong ~]$ start-all.sh
注:该脚本将会被弃用,建议使用start-dfs.sh and start-yarn.sh启动HADOOP。
2 启动HiveServer2
1)方法一
[hadoop@strong ~]$ hiveserver2
2)方法二
[hadoop@strong ~]$ hive --service hiveserver2
3 启动Beeline
1)方法一
[hadoop@strong ~]$ beeline
2)方法二
[hadoop@strong ~]$ hive --service beeline
beeline> !connect jdbc:hive2://localhost:10000/default
Connecting to jdbc:hive2://localhost:10000/default
Enter username for jdbc:hive2://localhost:10000/default: hadoop
Enter password for jdbc:hive2://localhost:10000/default: ******
Connected to: Apache Hive (version 2.3.3)
Driver: Hive JDBC (version 2.3.3)
Transaction isolation: TRANSACTION_REPEATABLE_READ
0: jdbc:hive2://localhost:10000/default>
注:进行连接出现如下错误时,需要对/usr/local/hadoop/etc/hadoop/core-site.xml进行配置
apache.hadoop.security.authorize.AuthorizationException): User: hadoop is not allowed to impersonate root (state=08S01,code=0)
增加配置内容为:
<property>
<name>hadoop.proxyuser.hadoop.hosts</name>
<value>*</value>
</property>
<property>
<name>hadoop.proxyuser.hadoop.groups</name>
<value>*</value>
</property>
三 Beeline介绍
1 Beeline示例
[hadoop@strong ~]$ beeline
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/local/apache-hive-2.3.3-bin/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/local/hadoop-2.7.6/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.3.3 by Apache Hive
beeline> !connect jdbc:hive2://localhost:10000/hive
Connecting to jdbc:hive2://localhost:10000/hive
Enter username for jdbc:hive2://localhost:10000/hive: hadoop
Enter password for jdbc:hive2://localhost:10000/hive: ******
Connected to: Apache Hive (version 2.3.3)
Driver: Hive JDBC (version 2.3.3)
Transaction isolation: TRANSACTION_REPEATABLE_READ
0: jdbc:hive2://localhost:10000/hive> show tables;
+-----------+
| tab_name  |
+-----------+
| city      |
| emp       |
| t_emp     |
| test      |
+-----------+
4 rows selected (0.432 seconds)
0: jdbc:hive2://localhost:10000/hive>
注:也可以通过如下方式进行连接和访问。
[hadoop@strong ~]$ beeline -u jdbc:hive2://localhost:10000/hive -n hadoop -p hadoop
2 Beeline命令
通过!<SQLLine 命令>的方式执行,本篇将演示部分SQLLine命令。
1)查看帮助信息
0: jdbc:hive2://localhost:10000/hive> !help
!addlocaldriverjar  Add driver jar file in the beeline client side.
!addlocaldrivername Add driver name that needs to be supported in the beelineclient side.
!all                Execute the specified SQL against all the current connections
!autocommit         Set autocommit mode on or off
!batch              Start or execute a batch of statements
!brief              Set verbose mode off
!call               Execute a callable statement
!close              Close the current connection to the database
!closeall           Close all current open connections
!columns            List all the columns for the specified table
!commit             Commit the current transaction (if autocommit is off)
!connect            Open a new connection to the database.
!dbinfo             Give metadata information about the database
!describe           Describe a table
!dropall            Drop all tables in the current database
!exportedkeys       List all the exported keys for the specified table
!go                 Select the current connection
!help               Print a summary of command usage
!history            Display the command history
!importedkeys       List all the imported keys for the specified table
!indexes            List all the indexes for the specified table
!isolation          Set the transaction isolation for this connection
!list               List the current connections
!manual             Display the BeeLine manual
!metadata           Obtain metadata information
!nativesql          Show the native SQL for the specified statement
!nullemptystring    Set to true to get historic behavior of printing null asempty string. Default is false.
!outputformat       Set the output format for displaying results(table,vertical,csv2,dsv,tsv2,xmlattrs,xmlelements, anddeprecated formats(csv, tsv))
!primarykeys        List all the primary keys for the specified table
!procedures         List all the procedures
!properties         Connect to the database specified in the properties file(s)
!quit               Exits the program
!reconnect          Reconnect to the database
!record             Record all output to the specified file
!rehash             Fetch table and column names for command completion
!rollback           Roll back the current transaction (if autocommit is off)
!run                Run a script from the specified file
!save               Save the current variabes and aliases
!scan               Scan for installed JDBC drivers
!script             Start saving a script to a file
!set                Set a beeline variable
!sh                 Execute a shell command
!sql                Execute a SQL command
!tables             List all the tables in the database
!typeinfo           Display the type map for the current connection
!verbose            Set verbose mode on
2)列出当前的连接信息
0: jdbc:hive2://localhost:10000/hive> !list
1 active connection:#0  open     jdbc:hive2://localhost:10000/hive3)执行清屏命令0: jdbc:hive2://localhost:10000/hive> !sh clear0: jdbc:hive2://localhost:10000/hive> 
4)格式化输出
0: jdbc:hive2://localhost:10000/hive> !outputformat vertical
0: jdbc:hive2://localhost:10000/hive> show tables;
tab_name  citytab_name  emptab_name  t_emptab_name  test4 rows selected (0.251 seconds)
0: jdbc:hive2://localhost:10000/hive> !outputformat table
0: jdbc:hive2://localhost:10000/hive> show tables;
+-----------+
| tab_name  |
+-----------+
| city      |
| emp       |
| t_emp     |
| test      |
+-----------+
4 rows selected (0.205 seconds)
3 Beeline Hive命令
当使用Hive JDBC驱动时,可以在Beeline运行Hive特定的命令(和Hive CLI命令一样)。
具体参考:Hive CLI初探
4 Beeline命令选项
[hadoop@strong ~]$ beeline --help
Usage: java org.apache.hive.cli.beeline.BeeLine -u <database url>               the JDBC URL to connect to-r                              reconnect to last saved connect url (in conjunction with !save)-n <username>                   the username to connect as-p <password>                   the password to connect as-d <driver class>               the driver class to use-i <init file>                  script file for initialization-e <query>                      query that should be executed-f <exec file>                  script file that should be executed-w (or) --password-file <password file>  the password file to read password from--hiveconf property=value       Use value for given property--hivevar name=value            hive variable name and valueThis is Hive specific settings in which variablescan be set at session level and referenced in Hivecommands or queries.--property-file=<property-file> the file to read connection properties (url, driver, user, password) from--color=[true/false]            control whether color is used for display--showHeader=[true/false]       show column names in query results--headerInterval=ROWS;          the interval between which heades are displayed--fastConnect=[true/false]      skip building table/column list for tab-completion--autoCommit=[true/false]       enable/disable automatic transaction commit--verbose=[true/false]          show verbose error messages and debug info--showWarnings=[true/false]     display connection warnings--showDbInPrompt=[true/false]   display the current database name in the prompt--showNestedErrs=[true/false]   display nested errors--numberFormat=[pattern]        format numbers using DecimalFormat pattern--force=[true/false]            continue running script even after errors--maxWidth=MAXWIDTH             the maximum width of the terminal--maxColumnWidth=MAXCOLWIDTH    the maximum width to use when displaying columns--silent=[true/false]           be more silent--autosave=[true/false]         automatically save preferences--outputformat=[table/vertical/csv2/tsv2/dsv/csv/tsv]  format mode for result displayNote that csv, and tsv are deprecated - use csv2, tsv2 instead--incremental=[true/false]      Defaults to false. When set to false, the entire result setis fetched and buffered before being displayed, yielding optimaldisplay column sizing. When set to true, result rows are displayedimmediately as they are fetched, yielding lower latency andmemory usage at the price of extra display column padding.Setting --incremental=true is recommended if you encounter an OutOfMemoryon the client side (due to the fetched result set size being large).Only applicable if --outputformat=table.--incrementalBufferRows=NUMROWS the number of rows to buffer when printing rows on stdout,defaults to 1000; only applicable if --incremental=trueand --outputformat=table--truncateTable=[true/false]    truncate table column when it exceeds length--delimiterForDSV=DELIMITER     specify the delimiter for delimiter-separated values output format (default: |)--isolation=LEVEL               set the transaction isolation level--nullemptystring=[true/false]  set to true to get historic behavior of printing null as empty string--maxHistoryRows=MAXHISTORYROWS The maximum number of rows to store beeline history.--help                          display this messageExample:1. Connect using simple authentication to HiveServer2 on localhost:10000$ beeline -u jdbc:hive2://localhost:10000 username password2. Connect using simple authentication to HiveServer2 on hs.local:10000 using -n for username and -p for password$ beeline -n username -p password -u jdbc:hive2://hs2.local:100123. Connect using Kerberos authentication with hive/localhost@mydomain.com as HiveServer2 principal$ beeline -u "jdbc:hive2://hs2.local:10013/default;principal=hive/localhost@mydomain.com"4. Connect using SSL connection to HiveServer2 on localhost at 10000$ beeline "jdbc:hive2://localhost:10000/default;ssl=true;sslTrustStore=/usr/local/truststore;trustStorePassword=mytruststorepassword"5. Connect using LDAP authentication$ beeline -u jdbc:hive2://hs2.local:10013/default <ldap-username> <ldap-password>

【Hive】Beeline CLI介绍相关推荐

  1. hive hive beeline常用参数

    Hive 1参数如下: usage: hive -d,--define <key=value> Variable substitution to apply to Hive command ...

  2. HIVE的安装配置、mysql的安装、hive创建表、创建分区、修改表等内容、hive beeline使用、HIVE的四种数据导入方式、使用Java代码执行hive的sql命令

    1.上传tar包 这里我上传的是apache-hive-1.2.1-bin.tar.gz 2.解压 mkdir -p /home/tuzq/software/hive/ tar -zxvf apach ...

  3. Hive beeline详解

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

  4. BigData之Hive beeline:beeline的简介、使用方法之详细攻略

    BigData之Hive beeline:beeline的简介.使用方法之详细攻略 目录 beeline的简介 beeline的使用方法 1.命令行参数解释 2.beeline的输出格式 2.1.ta ...

  5. 数仓工具—Hive Beeline(21)

    Beeline 前面我们介绍过hive 的命令行,其实就是hive 的老版命令行,你可以参考Hive命令行,今天我们介绍一下hive 新的命令行beeline,前面我们也介绍过如何在hive 命令行里 ...

  6. HIve:beeline终端上在输错hive语句时,无论 Backspace还是delete 都删除不掉错误的语句,没有办法退格...

    通过SecureCRT工具连上linux后,通过beeline连接上hive后,在输错hive语句时,无论 Backspace还是delete 都删除不掉错误的语句,没有办法退格. 解决方案: 第一步 ...

  7. Hive beeline常用操作

    目录 1 beeline连接hive 2 退出beeline 3 清屏 4 遇到的问题 1 beeline连接hive 两种方式,都需要先启动hiveserver2 hive --service hi ...

  8. 请问下这个hive beeline命令是啥意思。

    /bin/beeline -u 'jdbc:hive2://ddp-jsapp-d001:10000/s_it_cwt;principal=hive/ddp-jsapp-d001@EXAMPLE.CO ...

  9. 一文带你了解Hive【详细介绍】Hive与传统数据库有什么区别?

    大家早上好,本人姓吴,如果觉得文章写得还行的话也可以叫我吴老师.欢迎大家跟我一起走进数据分析的世界,一起学习! 感兴趣的朋友可以关注我或者我的数据分析专栏,里面有许多优质的文章跟大家分享哦. 前期回顾 ...

最新文章

  1. java应用窗口大小_java 如何让程序窗口随屏幕大小改变 | 学步园
  2. php验证码内置函数,刚写了一个PHP的高效验证码函数 | 学步园
  3. 优化JavaScript代码
  4. PAT甲级1001 A+B Format:[C++题解]字符串处理
  5. 微信公众平台开发(38)一站到底在线答题
  6. C语言实现ternary search三分查找算法(附完整源码)
  7. ps2改usb接口_简单易懂,改装任意手柄为Type-C接口的方法
  8. java中的工厂模式_深入理解Java的三种工厂模式
  9. VC++2010配置使用MySQL5.6
  10. 让你的git bash更好看更实用
  11. pytorch自定义loss损失函数
  12. seo代码优化工具_谁是「南京SEO」搜索引擎网站关键词排名优化专家
  13. Java GC机制详解
  14. 云南昭通暴雨强度公式_玉溪市中心城区暴雨强度公式
  15. 以太坊平台评估 私有链和联盟链的机会与挑战
  16. 天津电动自行车外贸出口认证GCC合格证
  17. 关于如何在mac系统上安装Git并在码市上建立项目
  18. [爬虫实战]利用python快速爬取NCBI中参考基因组assembly的相关信息
  19. Jmeter线程组之jp@gc - Stepping Thread Group
  20. 使用 HTML、CSS 和 JavaScript 的简单模拟时钟

热门文章

  1. 艺展中国-一代名家刘泽仲作品展
  2. 【小样本基础】Meta-Learning 元学习流程:图解MAML代码
  3. linux驱动开发简单示例
  4. unity3D 鼠标滚轮实现物体的大小缩放
  5. 读书笔记-在工作中保持充沛的体力
  6. “压缩(zipped)文件夹“G:\Program\Wechat WeChatFiles(wxid cqpx72n77z9x22 FileStorage\File 2022-12 基...
  7. 【Typora常用快捷键】
  8. 酷我音乐盒在听一遍就自己默认下载…
  9. “互联网+”下的数据化运营和技术架构
  10. 南京(选自 余秋雨《文化苦旅》)