Hive 資料抽象及資料庫操作

2021-08-20 07:20:15 字數 1935 閱讀 7142

ddl    data definition language

1)資料抽象

2)資料庫操作

資料庫:包含一系列的表,是對應hdfs上的乙個資料夾,預設是/user/hive/warehouse

1. 建立資料庫

create (database|schema) [if not exists] database_name

[comment database_comment]

[location hdfs_path]  

[with dbproperties (property_name=property_value, ...)];

例:① create database ruoze_hive;    // 對應hdfs目錄:/user/hive/warehouse/ruoze_hive.db

② create database if not exists ruoze_hive;    // 資料庫存在就忽略

③ create database ruoze_hive2 location "/ruoze_hive2";        

④ create database if not exists ruoze_hive3 

comment "it is my database"

with dbproperties ("creator"="ruoze", "date"="2018-02-08");  //有屬性描述的db

2. 修改資料庫 

alter (database|schema) database_name set dbproperties (property_name=value,...);  

-- (note: schema added in hive 0.14.0)

alter (database|schema) database_name set owner [user|role] user_or_role;    

//修改使用者

-- (note: hive 0.13.0 and later; schema added in hive 0.14.0)

alter (database|schema) database_name set location hdfs_path;       

-- (note: hive 2.2.1, 2.4.0 and later)

例:① alter database ruoze_hive3 set dbproperties ("update"="j");    //更改屬性

3. 刪除資料庫

drop (database|schema) [if exists] database_name [restrict|cascade];  

例:① drop database ruoze_hive2; 

異常:failed: execution error, return code 1 from org.apache.hadoop.hive.ql.exec.ddltask.

invalidoperationexception(message:database ruoze_hive2 is not empty. one or more tables exist.)

解決:--刪除資料庫下的表

--cascade可以級聯刪,但是生產禁止使用!!!從刪庫到跑路

3)meta資訊說明

1)dbs    資料庫db的總表。包括db_id, desc, db_location_uri, name 等

2)tbls    表資訊

3)database_params    資料庫屬性總表,鍵值對存在。包括db_id, param_key. param_value

4)table_params    表引數資訊

hadoop命令及hive資料庫操作語句的簡單使用

一 hadoop 1.hadoop查詢檔案屬性詳細資訊 du lh 2.如果沒有配置hadoop環境變數,則應到hadoop的bin目錄,執行hadoop命令,如 第一步 cd home hms hadoop hadoop 2.6.0 bin 第二步 hadoop fs ls userrepot 注...

Hive 6 資料庫操作

乙個資料庫對應與檔案系統中的乙個目錄。且他們的根目錄即是 hive.metastore warehouse dir配置項來設定的。比如我這裡就是 user henvealf hive warehouse 剛開始進入 hive 命令行時,預設位於名為 default 的預設資料庫中。其資料目錄就在 u...

實戰 hive 資料庫SQL操作

hive default create database if not exists testdb 檢視所有已建立的資料庫 hive default show databases 匹配查詢資料庫 查詢test開頭,且後續有字元的資料庫 hive default show databaseslike ...