好玩的大数据之19:Hive实验2(hive beeline)

一、简介


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

Beeline支持嵌入模式(embedded mode)和远程模式(remote mode)。在嵌入式模式下,运行嵌入式的Hive(类似Hive CLI),而远程模式可以通过Thrift连接到独立的HiveServer2进程上。从Hive 0.14版本开始,Beeline使用HiveServer2工作时,它也会从HiveServer2输出日志信息到STDERR。

二、启动

        1)启动前确保hiveserver2服务已经运行        

                启动hive服务

                        hive --service metastore > $HIVE_HOME/working/logs/metastore.log 2>&1 &

                启动hiveserver2服务

                        hive --service hiveserver2 > $HIVE_HOME/working/logs/hiveserver2.log 2>&1 &

                检查

                        sudo netstat -tulnp | grep 10000

hiveserver2服务

                        ps -ef|grep hiveserver2

        2)beeline  --help

一定要善用help,不懂就问help 

Usage: java org.apache.hive.cli.beeline.BeeLine

  -u <database url>              the JDBC URL to connect to

   -n <username>                  the username to connect as

  -p <password>                  the password to connect as

   -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

  --help                          display this message

  Example:

    1. Connect using simple authentication to HiveServer2 on localhost:10000

    $ beeline -u jdbc:hive2://localhost:10000 username password

    2. 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:10000/default

        3)启动beeline

                beeline -u jdbc:hive2://master:10000

                或者

                beeline

                        !connect jdbc:hive2://master:10000

                在NONE认证方式下,以上命令会直接进入beeline shell

三、命令行help


在beeline下输入help,会展示所有的beeline命令

help

!addlocaldriverjar  Add driver jar file in the beeline client side.

!addlocaldrivername Add driver name that needs to be supported in the beeline

                    client 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

!delimiter          Sets the query delimiter, defaults to ;

!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 as

                    empty string. Default is false.

!outputformat      Set the output format for displaying results

                    (table,vertical,csv2,dsv,tsv2,xmlattrs,xmlelements, and

                    deprecated 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

四、命令行实例


    1.select version();

     2.list

    2.list

            !list


                





六、配置和排错


1.用beeline/hive操作时,如何关闭打印多余的info?

        a) 在使用beeline时加入以下设置即可–hiveconf hive.server2.logging.operation.level=NONE

        b) 或者在hive-site.xml中加入如下配置也可以禁用在beeline中显示额外信息

    <property>

    <name>hive.server2.logging.operation.enabled</name>

    <value>false</value>

  </property>

  <property>

    <name>hive.server2.logging.operation.log.location</name>

    <value>/mylab/soft/apache-hive-3.1.2-bin/working/operation_log</value>

  </property>

2.关于认证

hive.site中搜    hive.server2.authentication,有以下内容

<property>

    <name>hive.server2.authentication</name>

    <value>NONE</value>

    <description>

      Expects one of [nosasl, none, ldap, kerberos, pam, custom].

      Client authentication types.

        NONE: no authentication check

        LDAP: LDAP/AD based authentication

        KERBEROS: Kerberos/GSSAPI authentication

        CUSTOM: Custom authentication provider

                (Use with property hive.server2.custom.authentication.class)

        PAM: Pluggable authentication module

        NOSASL:  Raw transport

    </description>

  </property>

<property>

    <name>hive.server2.thrift.client.user</name>

    <value>anonymous</value>

    <description>Username to use against thrift client</description>

  </property>

  <property>

    <name>hive.server2.thrift.client.password</name>

    <value>anonymous</value>

    <description>Password to use against thrift client</description>

  </property>

   默认认证方式为NONE

   默认用户名/密码配置为anonymous/anonymous

   需要时,设定用户名和密码

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 162,710评论 4 376
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 68,839评论 2 308
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 112,295评论 0 255
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,776评论 0 223
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 53,198评论 3 297
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 41,074评论 1 226
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 32,200评论 2 322
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,986评论 0 214
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,733评论 1 250
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,877评论 2 254
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,348评论 1 265
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,675评论 3 265
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,393评论 3 246
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,209评论 0 9
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,996评论 0 201
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 36,212评论 2 287
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 36,003评论 2 280