hive常見命令

2021-10-02 19:52:04 字數 2292 閱讀 6914

hive常用命令

1、進入hive資料庫:hive

2、檢視hive中的所有資料庫:show databases;

3、用default資料庫:use default;

4、檢視所有的表:show tables;

5、查詢表結構:desc mytest(表名);

6、查詢表資料: select * from mytest(表名);

7、建立資料庫:hive> create schema userdb;

8、驗證資料庫表:hive> show databases;

9、刪除資料庫:hive> drop database if exists userdb;

hive> drop schema userdb;

全部刪除相應的表在刪除資料庫之前:hive> drop database if exists userdb cascade;

10、建立表employee

hive> create table if not exists employee (eid int,name string,salary string,destination string)

> comment 'employee details'

> row format delimited

> fields terminated by '\t'

> lines terminated by '\n'

stored as textfile;

如果增加分割槽必須在建立表的時候就建立分割槽,不然就會報錯,建立分割槽的命令》partition by 『根據哪個字段分割槽』,

hive> create table employee (id int, name string, dept string)

> partitioned by (year int)

> row format delimited

> fields terminated by '\t'

> lines terminated by '\n'

> stored as textfile;

stored as textfile檔案格式,檔案格式在hive中有三種: textfile、sequencefile(序列化檔案,學hadoop的都會知道啦)、rcfile。

11、新增資料到表中

hive> load data local inpath 『/usr/hadoop/hive/sample.txt』

> overwrite into table employee;
如果table是個分割槽表則必須在hql中指定分割槽

hive> load data local inpath 『/usr/hadoop/hive/sample.txt』

> overwrite into table employee partition(year=2012);(雖然已經實現了分割槽,但還未明白為什麼分割槽後所有的資料都根據分割槽條件發生變化)
插入表資料:insert into employee(eid,name) values (1208,『jack』);hive只支援插入不支援修改和刪除

12、重新命名表名: hive> alter table employee rename to emp;

13、修改emp表中字段name為ename: hive> alter table emp change name ename string;

14、修改emp表中字段salary的資料型別從float改為double:hive> alter table emp change salary salary double;

15、刪除表;hive> drop table test;

16、建立檢視

hive> create view empview as

> select * from emp where salary>40000;
17、不同型別的連線 join 、left outer join、right outer join、full outer join

18、建立外部表:用external關鍵字

hive> create external table outsidetable(name string comment 『name value』,addr string comment 『addr value』);

查詢表資訊:desc formatted outsidetable;

hive常見命令

clear 清屏 dfs lsr hive 執行dfs命令 show databases 檢視所有資料庫 okdefault time taken 1.693 seconds,fetched 1 row s 我們發現只有乙個default庫 於是我們使用default 資料庫 hive use de...

Hive 常見設定

1.hive中 null 太多會占用大量空間 用這個可以減少占用 alter table test null set serdeproperties serialization.null.format 2.使用 sqoop 從mysql 和hive的 互相匯入 mysql 中 空 底層是用 null...

hive常見問題

distinct用法 對select 後面所有欄位去重,並不能只對一列去重 1 當distinct應用到多個欄位的時候,distinct必須放在開頭,其應用的範圍是其後面的所有字段,而不只是緊挨著它的乙個字段,而且distinct只能放到所有欄位的前面 2 distinct對null是不進行過濾的,...