很多人会认为Hive命令行只是一个执行HQL语句的控制台,其实它没你想的那么简单,还有很多实用的用法,这里就简单介绍一下。
查看Hive的帮助文档
[hdfs@cdh01 ~]$ hive -H
usage: hive
-d,--define <key=value> Variable subsitution to apply to hive
commands. e.g. -d A=B or --define A=B
--database <databasename> Specify the database to use
-e <quoted-query-string> SQL from command line
-f <filename> SQL from files
-H,--help Print help information
--hiveconf <property=value> Use value for given property
--hivevar <key=value> Variable subsitution to apply to hive
commands. e.g. --hivevar A=B
-i <filename> Initialization SQL file
-S,--silent Silent mode in interactive shell
-v,--verbose Verbose mode (echo executed SQL to the
console)
[hdfs@hadoop-master ~]$ hive --help
Usage ./hive <parameters> --service serviceName <service parameters>
Service List: beeline cleardanglingscratchdir cli help hiveburninclient hiveserver2 hiveserver hwi jar lineage metastore metatool orcfiledump rcfilecat schemaTool version
Parameters parsed:
--auxpath : Auxillary jars
--config : Hive configuration directory
--service : Starts specific service/component. cli is default
Parameters used:
HADOOP_HOME or HADOOP_PREFIX : Hadoop install directory
HIVE_OPT : Hive options
For help on a particular service:
./hive --service serviceName --help
Debug help: ./hive --debug --help
使用hive -H和hive --help查看的帮助文档不一样,hive --help查看的是使用hive启动服务的帮助文档,hive -H是使用hive命令行的文档。
Hive启动服务
–auxpath是指定服务需要的扩展jar包,–config指定服务需要的配置参数,–service服务名
通过启动服务进入hive命令行
[hdfs@hadoop-master ~]$ hive --service cli
hive>
进入beeline命令行
[hdfs@hadoop-master ~]$ hive --service beeline
beeline>
Hive命令行
-f是用来执行hql脚本,执行完成返回结果
-i进入hive命令行前先初始化hql脚本
-e用来执行在hive命令行能够执行的所有命令,包括下面介绍的shell命令,hdfs命令等
–database指定进入hive命令所访问的数据库
-S用于忽略执行hive命令时一些日志输出
–hiveconf、–hivevar和–define类型,都是用于初始化hive变量
Hive执行Shell命令
Hive命令行是可以执行shell命令的,感叹号后面加上shell命令就可以执行了
[hdfs@hadoop-master ~]$ hive
hive> !pwd;
/var/lib/hadoop-hdfs
hive> !ls /var/lib/hadoop-hdfs;
100
death
presto-server-0.152
presto-server-0.152.zip
t_passenger.java
Hive执行HDFS命令
Hive命令行是可以执行HDFS命令的,直接使用dfs命令即可:
hive> dfs -ls /;
Found 11 items
drwxr-xr-x - hdfs supergroup 0 2019-07-31 17:29 /etl-shell
drwxr-xr-x - hdfs supergroup 0 2019-06-18 17:59 /logs
drwxr-xr-x - hdfs supergroup 0 2019-06-21 11:47 /test
drwxrwxrwt - hdfs supergroup 0 2019-08-30 10:46 /tmp
drwxrwxrwx - hdfs supergroup 0 2019-08-28 11:38 /user