zoukankan      html  css  js  c++  java
  • 大数据-Hive 常用命令

     Hive 启动

    ~$ hive 

    退出

    hive>quit;     --退出hive

    or

    hive> exit;    --exit会影响之前的使用,所以需要下一句kill掉hadoop的进程
    >hadoop job -kill jobid

    选择使用哪个数据库

    hive> use database_name;    --使用哪个数据库

    查看数据表结构

    hive> describe tab_name; or desc tab_name;   --查看表的结构及表的路径

    查看数据库的描述及路径

    hive> describe database database_name; 
    or
    hive> desc database database_name;
     --查看数据库的描述及路径

    Hive QL

    • 创建数据库
    -- 创建hello_world数据库
    create database hello_world; 
    -- 如果数据库已经存在就会抛出一个错误信息,使用如下语句可以避免抛出错误信息:
    create database if not exists database_name
    • 查看所有数据库
    show databases;
    • 查看所有表
    show tables;
    • 创建内部表
    -- 创建hello_world_inner
    create table hello_world_inner
    (
        id bigint, 
        account string, 
        name string,
        age int
    )
    row format delimited fields terminated by '	';
    • 创建分区表
    create table hello_world_parti
    (
        id bigint,
        name string
    )
    partitioned by (dt string, country string)
    ;
    • 展示表分区
    show partitions hello_world_parti;
    • 更改表名称
    alter table hello_world_parti to hello_world2_parti;
    • 删除数据表
    hive>drop table t1 ;      --删除表t1
    or
    hive> drop table if exists t1;
    • 可以用下面的命令来修改数据库的路径:
    hive> create database database_name location '路径';   
    
    hive> drop database if exists database_name; --删除空的数据库
    
    hive> drop database if exists database_name cascade; --先删除数据库中的表再删除数据库
    • 导入数据
    load data local inpath '/home/deploy/user_info.txt' into table user_info;

    导入数据的几种方式

    比如有一张测试表:

    create table hello
    (
    id int,
    name string,
    message string
    )
    partitioned by (
    dt string
    )
    ROW FORMAT DELIMITED
    FIELDS TERMINATED BY '	'
    STORED AS TEXTFILE
    ;
    • 从本地文件系统中导入数据到hive表
    load data local inpath 'data.txt' into table hello;
    • 从HDFS上导入数据到hive表
    • 从别的表中查询出相应的数据并导入到hive表中
    • 创建表时从别的表查到数据并插入的所创建的表中

     

  • 相关阅读:
    ibatis $与#的区别
    (转载)Hibernate与Jpa的关系
    tomcat web工程 jar包冲突解决方法
    jquery 获取checkbox 选中值并拼接字符集
    mysql BLOB字段转String的方法
    Ajax工作原理
    Spring mvc 具体RequestMapping 参数含义
    覆盖bootstrap的样式
    开园啦,致曾经现在以后的自己~
    SimpleDateFormat 常规用法
  • 原文地址:https://www.cnblogs.com/BlueSkyyj/p/9635841.html
Copyright © 2011-2022 走看看