好玩的大數(shù)據(jù)之19:Hive實驗2(hive beeline)

一、簡介


Hive客戶端工具后續(xù)將使用Beeline?替代HiveCLI?,并且后續(xù)版本也會廢棄掉HiveCLI?客戶端工具,Beeline是?Hive 0.11版本引入的新命令行客戶端工具,它是基于SQLLine CLI的JDBC客戶端。

Beeline支持嵌入模式(embedded mode)和遠(yuǎn)程模式(remote mode)。在嵌入式模式下,運行嵌入式的Hive(類似Hive CLI),而遠(yuǎn)程模式可以通過Thrift連接到獨立的HiveServer2進(jìn)程上。從Hive 0.14版本開始,Beeline使用HiveServer2工作時,它也會從HiveServer2輸出日志信息到STDERR。

二、啟動

? ? ? ? 1)啟動前確保hiveserver2服務(wù)已經(jīng)運行? ? ? ??

????????????????啟動hive服務(wù)

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

????????? ??????啟動hiveserver2服務(wù)

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

? ? ? ? ? ? ? ? 檢查

????????????????????????sudo netstat -tulnp | grep 10000

hiveserver2服務(wù)

? ? ? ? ? ? ? ? ? ? ? ? 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認(rèn)證方式下,以上命令會直接進(jìn)入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操作時,如何關(guān)閉打印多余的info?

????????a) 在使用beeline時加入以下設(shè)置即可–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.關(guān)于認(rèn)證

hive.site中搜? ??hive.server2.authentication,有以下內(nèi)容

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

? ?默認(rèn)認(rèn)證方式為NONE

? ?默認(rèn)用戶名/密碼配置為anonymous/anonymous

? ?需要時,設(shè)定用戶名和密碼

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容