您当前的位置: 首页 >  hive

梁云亮

暂无认证

  • 2浏览

    0关注

    1211博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Hive常用Shell命令

梁云亮 发布时间:2020-02-17 10:22:37 ,浏览量:2

  • 在启动Hive之前,必须先启动hdfs和yarn

    $ sbin/start-dfs.sh $ sbin/start-yarn.sh

  • 启动hive。

    $ bin/hive

  • 查看数据库

    hive> show databases;

  • 打开默认数据库

    hive> use default;

  • 显示default数据库中的表

    hive> show tables;

  • 创建一张表

    hive> create table student(id int, name string);

  • 显示数据库中有几张表

    hive> show tables;

  • 查看表的结构

    hive> desc student;

  • 向表中插入数据

    hive> insert into student values(1000,“ss”);

  • 查询表中数据

    hive> select * from student;

  • 不进入hive的交互窗口执行sql语句

    $ hive -e “select id from stu”;

  • 执行脚本中sql语句

    1. 在linux本地目录中创建hive.sql文件

      [hc@hcmaster datas]$ touch hive.sql

    2. 在文件中写入正确的sql语句

      select *from student;

    3. 执行文件中的sql语句

      $ hive -f /usr/local/test/hive.sql

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

      $ hive -f /usr/local/test/hive.sql > /usr/local/test/hive_res.txt

  • 查看hdfs文件系统

    hive(default)>dfs -ls /;

  • 查看本地文件系统

    hive(default)>! ls /usr/local/test;

  • 查看在hive中输入的所有历史命令:进入到当前用户的根目录home/hc,查看. hivehistory文件

    [hc@hcmaster ~]$ cat .hivehistory

  • 退出hive

    hive> quit;

关注
打赏
1665409997
查看更多评论
立即登录/注册

微信扫码登录

0.0416s