Hive常用的几种交互操作

查看hive下的交互命令方式 -help(hive 外)

命令:bin/hive -help
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

-e <引号括起来的查询字符串> sql命令行

  • 查询样例

“select * from db_hive.student;”
好处:不用直接进入到hive的交互是命令页面

《Hive常用的几种交互操作》 -e

-f <一个sql文件> 一个包含sql或者业务逻辑的sql文件

  • $ touch hivef.sql 创建一个sql文件

    文件内容:select * from db_hive.student ;

  • 执行此文件

    $ bin/hive -f /opt/datas/hivef.sql

  • 把执行结果输出到某个文件(保存执行结果)

    $ bin/hive -f /opt/datas/hivef.sql > /opt/datas/hivef-res.txt
    《Hive常用的几种交互操作》 总过程

– i <文件名>初始化sql文件

  • bin/hive -i <filename>
    与用户自定义相互使用

hive命令中的交互模式(hive内)

  • 退出 exit

  • quit

  • set key=value
    例如: set system:user.name=lizh

    《Hive常用的几种交互操作》

    说明:图片中的所有key的value都可以进行设置。

  • !(感叹号)hive客户端内使用本地文件系统linux命令则用感叹号!即可

    命令:!ls /opt/datas/ ;

    《Hive常用的几种交互操作》

  • 在hive cli命令窗口中如何查看hdfs文件系统
    hive (default)> dfs -ls / ;
    说明:必须是dfs开头。它模式是吧bin/hdfs 省略掉了。
    注意:内部命令都是以分号结尾

    《Hive常用的几种交互操作》 结尾

  • 查询语句
    select * from student ;

    《Hive常用的几种交互操作》 query String

    原文作者:志辉聊码
    原文地址: https://www.jianshu.com/p/8f6e53c8f3d9
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞