二 hive库 表 数据加载 简介

2 hive库 表 数据加载 简介

 

 

1 库操作

  

hive>create database    // 位于 user/hive/warehouse/mydb
[if not exists] mydb  
[location] '/.......'  
[comment] '....';

hive>show databases;

hive>describe database mydb;

hive> drop database  if existed mydb cascade;

 

 

 

2 表操作:

 

hive>CREATE TABLE IF NOT EXISTS t1(...) 
[COMMENT '....'] 
[LOCATION '...']

hive>SHOW TABLES in mydb;    查看mydb数据库下的所有表

hive>CREATE TABLE t2 LIKE t1;  根据t1结构定义t2表的结构,

hive>DESCRIBE t2;

 

查看更详细信息 比如如下可以看到t1在hdfs文件路径 .和操作这个文件的输入 输出format类类型

TextInputFormat HiveIgnoreKeyTextOutputFormat 

hive (default)> describe extended t1;   
OK
col_name        data_type       comment
username                string                                      
                 
Detailed Table Information      Table(tableName:t1, dbName:default, owner:root, createTime:1426309182, lastAccessTime:0, retention:0, sd:StorageDescriptor(cols:[FieldSchema(name:username, type:string, comment:null)], location:hdfs://h2single:9000/user/hive/warehouse/t1, inputFormat:org.apache.hadoop.mapred.TextInputFormat, outputFormat:org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat, compressed:false, numBuckets:-1, serdeInfo:SerDeInfo(name:null, serializationLib:org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe, parameters:{serialization.format=1}), bucketCols:[], sortCols:[], parameters:{}, skewedInfo:SkewedInfo(skewedColNames:[], skewedColValues:[], skewedColValueLocationMaps:{}), storedAsSubDirectories:false), partitionKeys:[], parameters:{transient_lastDdlTime=1426309182}, viewOriginalText:null, viewExpandedText:null, tableType:MANAGED_TABLE)
Time taken: 0.463 seconds, Fetched: 3 row(s)