zoukankan      html  css  js  c++  java
  • Hive-基本操作

    安装 Hive:https://www.cnblogs.com/jhxxb/p/11606842.html

    # 启动 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
    hive> quit;

    将本地文件导入 Hive

    cd /opt/
    vim student.txt
    
    # 注意以 tab 键间隔
    1001    zhangshan
    1002    lishi
    1003    zhaoliu
    
    
    # 启动 hive
    bin/hive
    
    # 显示数据库
    show databases;
    
    # 使用 default 数据库
    use default;
    
    # 显示 default 数据库中的表
    show tables;
    
    # 删除已创建的 student 表
    drop table student;
    
    # 创建 student 表, 并声明文件分隔符’	’
    create table student(id int, name string) ROW FORMAT DELIMITED FIELDS TERMINATED BY '	';
    
    # 加载/opt/module/data/student.txt 文件到 student 数据库表中。
    load data local inpath '/opt/student.txt' into table student;
    # Hive 查询结果
    select * from student;
    
    OK
    1001 zhangshan
    1002 lishi
    1003 zhaoliu
    Time taken: 0.085 seconds, Fetched: 3 row(s)
  • 相关阅读:
    2021/3/12
    2021/3/11
    2021/3/10
    2021/3/9
    2021/3/8
    2021/3/5
    2021/3/4
    2021/3/3
    2021/3/2
    2021/3/1
  • 原文地址:https://www.cnblogs.com/jhxxb/p/11608568.html
Copyright © 2011-2022 走看看