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;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM