hive的shell技巧
只执行一次Hive命令
通过shell的参数-e可以执行一次就运行完的命令
[root@tianqinglong01 hive]# hive -e "select * from qfdb.t_user"
[root@tianqinglong01 hive]# hive --database qfdb -e "select * from t_user"
单独执行一个sql文件
[root@tianqinglong01 ~]# vim query.hql
select * from t_user;
[root@tianqinglong01 ~]# hive -f query.hql
执行Linux命令
在Hive的shell中加上前缀!最后以分号;结尾,可以执行linux的命令
hive> !pwd
hive> !ls /root
执行HDFS命令
用户可以在Hive的shell中执行HDFS的DFS命令,不用敲入前缀hdfs或者hadoop
hive> dfs -ls /
显示当前库
下面是通过配置文件hive-site.xml显示
<property>
<name>hive.cli.print.current.db</name>
<value>true</value>
</property>
[root@tianqinglong01 hive]# cd conf/
[root@tianqinglong01 conf]# vim hive-site.xml
添加配置
启动
第二种
[root@tianqinglong01 conf]# vim .hiverc
set hive.cli.print.current.db=true
启动
local模式
set hive.mode.local.auto=true; (建议打开)
本文介绍了在Hive shell中执行一次性命令、运行SQL文件、调用Linux和HDFS命令的方法,以及如何显示当前数据库,并提供了配置hive-site.xml和.hiverc文件的示例,帮助用户更高效地操作Hive。
274

被折叠的 条评论
为什么被折叠?



