hive>hive -help
hive [-hiveconf x=y]* [<-i filename>]* [<-f filename>|<-e query-string>] [-S] -i 从文件初始化HQL -e 从命令行执行指定的HQL -f 执行HQL脚本 -v 输出执行的HQL语句到控制台 -p <port> connect to Hive Server on port number -hiveconf x=y Use this to set hive/hadoop configuration variables ;
Hive 交互式Shell命令:
- 当命令
$HIVE_HOME/bin/hive
以不带-e/-f
选项的方式运行时, hive将进入到交互模式以";"冒号结束命令行 ;
Sample Usage:
hive> set mapred.reduce.tasks=32; hive> set; hive> select a.* from tab1; hive> !ls; hive> dfs -ls;
Hive 命令行示例
##从命令行执行指定的sql语句
$HIVE_HOME/bin/hive -e 'select a.col from tab1 a' ;
##以指定的hive环境变量执行指定的sql语句
$HIVE_HOME/bin/hive -e 'select a.col from tab1 b' -hiveconf hive.exec.scratchdir=/home/my/hive_scratch -hiveconf mapred.reduce.tasks=32 ;
##以沉默模式执行指定的sql语句,并将执行结果导出到指定文件
$HIVE_HOME/bin/hive -e 'select a.col from tab1 c' > tablec.txt ;
##以非交互式模式执行sql文件
$HIVE_HOME/bin/hive -f /home/my/hive-script.sql ;
##在进入交互模式之前,执行初始化sql文件
$HIVE_HOME/bin/hive -i /home/my/hive-init.sql ;
show command :
- show databases [LIKE 'identifier_with_wildcards'] ;
- show create table ([db_name.]table_name|view_name);
- show tables [IN database_name] ;
- show columns (FROM|IN) table_name [(FROM|IN) db_name];
- show tblproperties tblname("dfs_");
- show partitions ;
- show partitions table_name PARTITION(ds='2020-03-03');
- show functions "fun_*";
- desc extended t_name;
- desc formatted table_name;