hive的基本用法:
(1)help命令
hadoop@hadoop-Lenovo-IdeaPad-Y470:~$ <span style="background-color: rgb(192, 192, 192);">hive --help</span><span style="color:#FF0000;">//help选项</span>
Usage ./hive <parameters> --service serviceName <service parameters>
<span style="color:#FF0000;">Service List: beeline cli help hiveserver2 hiveserver hwi jar lineage metastore metatool orcfiledump rcfilecat schemaTool</span>//可用的服务
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:
<span style="color:#FF0000;">./hive --service serviceName --help//service帮助</span>
Debug help: ./hive --debug --help
---------service serviceName --help例子:
<span style="background-color: rgb(153, 153, 153);">hive --service cli --help</span>
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
-h <hostname> connecting to Hive Server on remote host
--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
-p <port> connecting to Hive Server on port number
-S,--silent Silent mode in interactive shell
-v,--verbose Verbose mode (echo executed SQL to the
console)
(2)变量的命名空间:
1.hivevar(用户变量设置的地方) 2.hiveconf 3.system 可读可写 4.env 只读
2-1变量的生命:
set hivevar:变量名=值
例子:
set hivevar:zhu=ming;
create table test( ${hivevar:zhu} string );
describe test;
drop table test;
*注:hive中的“一次性”查询
hive -e ”select * from test;select * from test1“ >>/home/hadoop/out
进行两次查询,并将输出结果重定向
(3)hive中的查询方式:
3-1:从文件中载入命令查询:
方法一:
hive -f /home/hadoop/test.hql
方法二(在hive的cli中):
source /home/hadoop/test.hql
3-2:加载数据:
load data local inpath '/home/hadoop/testdata' into table test;
3-3:使cli在启动的时候进行一些预先操作:
hive --service cli -i//使用-i参数的时候,hive会自动在”/home/用户名/.hiverc"文件 并执行其中的命令
(4)cli的其他一些介绍:
4-1:在cli中使用shell命令:
<span style="color:#FF0000;">!</span> pwd
4-2:在cli中执行hadoop命令:
dfs -ls /