一、简介
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
ps -ef|grep hiveserver2
2)beeline --help
一定要善用help,不懂就问help
Usage: java org.apache.hive.cli.beeline.BeeLine
-u
-n
-p
-e
-f
-w (or) --password-file
--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中显示额外信息
2.关于认证
hive.site中搜 hive.server2.authentication,有以下内容
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
默认认证方式为NONE
默认用户名/密码配置为anonymous/anonymous
需要时,设定用户名和密码