Hive常用交互命令

1 Hive 常用交互命令

  • 1.“-e”不进入 hive 的交互窗口执行 sql 语句

    • bin/hive -e "select id from student;"
  • 2.“-f”执行脚本中 sql 语句

    • 在/opt/module/datas 目录下创建 hivef.sql 文件 touch hivef.sql

      -- 文件中写入正确的 sql 语句 
      select *from student;
      
    • 执行文件中的 sql 语句

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

    • 执行文件中的 sql 语句并将结果写入文件中

      bin/hive -f /opt/module/datas/hivef.sql > /opt/module/datas/hive_result.txt

2 Hive 其他命令操作

  • 退出 hive 窗口

    hive(default)>exit;
    hive(default)>quit; 
    在新版的 hive 中没区别了,在以前的版本是有的:
    exit:先隐性提交数据,再退出; 
    quit:不提交数据,退出;
    
  • 在 hive cli 命令窗口中如何查看 hdfs 文件系统

    hive(default)>dfs -ls /;

  • 在 hive cli 命令窗口中如何查看本地文件系统

    hive(default)>! ls /opt/module/datas;

  • 查看在 hive 中输入的所有历史命令

    • 进入到当前用户的根目录

    • 查看. hivehistory 文件

      [atguigu@hadoop102 ~]$ cat .hivehistory

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。