Hive基本使用——命令行

Hive 用户接口主要有三个:命令行(CLI),客户端(Client) 和 Web界面(WUI)。其中最常用的是 CLI,启动的时候,会同时启动一个 Hive 服务。Client 是 Hive 的客户端,用户连接至 Hive Server。在启动 Client 模式的时候,需要指出 Hive Server 所在节点,并且在该节点启动 Hive Server。 WUI 是通过浏览器访问 Hive的Web工具

这里介绍Hive命令行的一个基本使用

注意

hive命令行语句后面一定要加分号

创建数据库

hive> create database zwctest;

查看数据库

hive> show databases;
OK
default
zwctest
Time taken: 0.019 seconds, Fetched: 2 row(s)

切换数据库

切换数据库的时候可以输入:use database_name;

hive> use zwctest;
OK
Time taken: 0.012 seconds

删除数据库

hive> drop database if exists zwctest;

创建表

创建一个外部表,表有字段name,sex,age。comment后面内容为字段描述信息。

hive> create external table if not exists studenttable(
    > name string comment 'name value',
    > sex string comment 'sex value',
    > age string comment 'age value')
    > row format delimited
    > fields terminated by '\t'
    > lines terminated by '\n'
    > stored as textfile;
OK
Time taken: 0.163 seconds

查看所有表

hive> show tables;
OK
testtable
Time taken: 0.023 seconds, Fetched: 1 row(s)

查看表信息

hive> desc studenttable;
OK
name                    string                  name value          
sex                     string                  sex value           
age                     string                  age value      

#这里面有一个字段data,是string类型的,描述信息comment是“d comment”。

查看拓展描述信息

hive> describe formatted studenttable;
OK
# col_name              data_type               comment             
                 
name                    string                  name value          
sex                     string                  sex value           
age                     string                  age value           
                 
# Detailed Table Information             
Database:               zwctest                  
Owner:                  root                     
CreateTime:             Sun Oct 23 17:52:38 CST 2016     
LastAccessTime:         UNKNOWN                  
Protect Mode:           None                     
Retention:              0                        
Location:               hdfs://test1:8020/user/hive/warehouse/zwctest.db/studenttable    
Table Type:             EXTERNAL_TABLE           
Table Parameters:                
        EXTERNAL                TRUE                
        transient_lastDdlTime   1477216358          
                 
# Storage Information            
SerDe Library:          org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe       
InputFormat:            org.apache.hadoop.mapred.TextInputFormat         
OutputFormat:           org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat       
Compressed:             No                       
Num Buckets:            -1                       
Bucket Columns:         []                       
Sort Columns:           []                       
Storage Desc Params:             
        field.delim             \t                  
        line.delim              \n                  
        serialization.format    \t                  
Time taken: 0.055 seconds, Fetched: 31 row(s)

注:desc为简写,可写全拼describe

删除表

hive> drop table testtable;
OK
Time taken: 0.198 seconds

表加载数据

hive> load data local inpath '/data/apps/test/zhangwenchao/data/data.txt' into table studenttable; 
Loading data to table zwctest.studenttable
Table zwctest.studenttable: [numFiles=1, totalSize=2117]
OK
Time taken: 0.659 seconds

查看数据

select * from testtable;

点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )

Hive基本使用——命令行 - HelloWorld