drop database if exists 数据库名 cascade ;//数据库里有表,删不掉,需用强制删除 create table test(id string, name string, age int); CREATE TABLE table( id STRING, name STRING, age INT) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' LOCATION '/test0923'; vi t2.tsv hadoop fs -put t2.tsv /test0923/ hadoop fs -ls /test0923 select * from t2; CREATE TABLE t3( id STRING, name STRING, age INT) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' e1: sogou 500w数据,创建一张表sogou_20111230,这张表在sogou这个数据库中,注意,6个字段的数据类型. e2: 把sogou 500w的数据放到表中,并执行下面的查询, 查询前100行数据 select * from sogou.sogou_20111230 limit 100; SELECT uid FROM sogou_20111230 limit 10; 2011-12-30 00:00:08 timestamp 20111230000008 string select `order` from sogou_20111230 order by `order` limit 10; //order是关键字,不能直接用作列名 e3: sogou_20111230_2 \t -> , hive> CREATE TABLE sogou_20111230( > ts string, > uid string, > keyword string, > rank int, > order int, > url string) > ROW FORMAT DELIMITED > FIELDS TERMINATED BY '\t' > LOCATION '/sogoudata'; 1. 内部表 CREATE TABLE t1(id int); LOAD DATA LOCAL INPATH '/root/id' INTO TABLE t1; CREATE TABLE t2(id int, name string) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'; 2. 外部表MBNM hadoop fs -put id /external/id create external table t5(id int) location '/external'; 关键字external 告诉Hive这个表是外部表,删除该表并不会删除掉这份数据,不过描述表的元数据信息会被删除掉,元数据信息存储在mysql中 describe extended s1;//tableType:MANAGED_TABLE) describe extended s2;// tableType:EXTERNAL_TABLE) 3. 分区表 CREATE TABLE t3(id int) PARTITIONED BY (day int); --partitioned LOAD DATA LOCAL INPATH '/root/id' INTO TABLE t1 PARTITION (day=20); --partition 修改列名 IUYTREWQ : hive> alter table test > change column stuname name string; describe test; 增加列: hive> alter table test add columns( > height int); describe test; 替换列: hive> alter table test replace columns( > id int, > name string, > age int); 为表添加属性: hive> alter table test set tblproperties ( > 'note'='hello welcome'); show create table test; ======================================== 创建带有分区的内部表: hive> create table testpar( > id int, > name string,age int) PARTITIONED BY (day string) > ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' > location '/testpar'; 为带有分区的内部表加载数据: hive> load data local inpath '/home/zkpk/test' into table testpar > partition (day='0925'); 添加防止删除的保护: hive> alter table testpar > partition (day='0925') enable no_drop; 测试:删除分区 hive> alter table testpar drop if exists partition (day='0925'); 删除添加的"删除"保护: hive> alter table testpar > partition (day='0925') disable no_drop; 添加防止查询的保护: hive> alter table testpar > partition (day='0925') enable offline; 删除防止查询的保护: hive> alter table testpar > partition (day='0925') disable offline; select * from testpar;