hive常用命令

2021-09-17 00:11:58 字數 2935 閱讀 2779

hive的語法與mysql、oracle的語法類似,所以可以將mysql、oracle的語法在hive中使用,自己要勇於嘗試。

show

databases

;

describe

database

'資料庫名'

create

database

'資料庫名'

;

show

tables

;

create

table

'表名'

;

desc formatted '表名'
alter

table

'表名'

rename

to'新錶名'

drop

database

'資料庫名'

drop

table

'資料表名'

alter

table

'表名'

add|

replace

columns

('字段'

'資料型別'

)

注:add是表示新增乙個字段,新增字段位置在所有已經存在字段之後,分割槽的虛擬字段之前,replace表示替換表中所有的字段(這個幾乎不使用)

原始表結構[student(a string,b int,c int)]

alter

table

'表名'

(student) change a a1 int

注:修改欄位名

alter

table

'表名'

(student) change a a1 string after b

注:修改欄位名和對應的資料型別,並且改變欄位的順序(將字段a1置於欄位b之後)

alter

table

'表名'

(student) change c c1 string first

注:修改欄位名和對資料型別,並且將改變欄位的順序(將字段c1放在首位)

turncate table

'資料表名'

注:此操作只會清除資料表中的所有資料,不會刪除表結構。

create

table t1(id int

,name string)

row format delimited fields

terminated

by','

create external  table t2 (id int

,name string)

row format delimited fields

terminated

by','

在hive中使用』external』關鍵字來建立外部表;所以在建立資料表時,只要沒有使用關鍵字"external"建立的資料表都是內部資料表;反之,即為外部表。

在刪除內部資料表時,會連同hdfs中儲存的資料文字一起刪除,而刪除外部資料表時,只是在資料庫中刪除了該資料表的對映(元資料),hdfs儲存的資料文字不會被刪除,一旦再建立該資料表時,不用匯入資料,該表中原先的資料仍然存在。

create

table book (id bigint

, name string) partitioned by

(pubid int

)row format delimited fields

terminated

by','

alter

table

'資料表名'

drop

ifexists

partition

('字段'

='具體資料'

)

注:'if exists』是判斷語句,表示,如果存在這個分割槽,就將這個分割槽表刪除;'字段』表示在建立分割槽表時,使用的那個分割槽字段。

alter

table 表名 partition

('字段'

='具體資料'

)rename

topartition

('字段'

='具體資料'

)

show partitions '分割槽表名'
注:此命令只適用分割槽表。

show functions
create

table book (id bigint

, name string)

clustered

by(id)

into

4 backets row format delimited fields

terminated

by','

hive常用命令

進入hive目錄後執行hive命令進入命令模式 建立新錶 hive create table t hive a int,b int,c int row format delimited fields terminated by t 匯入資料t hive.txt到t hive表 hive load d...

hive常用命令

建立新錶 hive create table t hive a int,b int,c int row format delimited fields terminated by t 匯入資料t hive.txt到t hive表 hive load data local inpath home co...

Hive常用命令

檢視hdfs路徑 show create table table name 建表 create table tbname var1 char type1,var2 char type2 載入資料到表 刪除表 drop table tbname if expr1,expr2,expr3 expr1 判...