1. 程式人生 > >Hive對資料庫database的建立、修改

Hive對資料庫database的建立、修改

前言:Hive中對database的建立、查詢、location、修改、刪除等操作,作了簡單描述

1.建立資料庫
        hive>create database myhive;
        hive>create database if not exists myhive;
2.查詢資料庫和表
       hive>show databases;
       hive>show tables;
      使用正則表示式:
      hive>show databases like   'h.*';

3.修改資料庫預設位置
    hive>create database myhive  
            >location  'my/myhive.db';        //要指定資料庫名
        1)為資料庫增加描述資訊
                  hive>create database myhive
                         >comment 'this is my';
                 hive> desc database myhive;  //顯示詳細資訊
                       
       2)增加一些和其相關的鍵-值對屬性資訊
                 hive>create database myhive
                        >with dbproperties('name'='lu','data'='2012-01-02');
                 檢視:hive>desc database extended

myhive;
                 hive>use default;
   
       3)刪除資料庫
                 hive>drop database if exists myhive;          //避免資料庫不存在而丟擲警告資訊
                如果資料庫下有表,就不允許刪除;要是刪除的話,則:
                hive>drop database if exists myhive cascade;
                  restrict(預設)不允許刪除;
 4.修改資料庫
           為資料庫的dbproperties設定鍵值對屬性值,來描述資料庫屬性資訊,
   資料庫其他元資料都是不可更改的,包括資料庫名和資料庫所在目錄位置
               hive>alter database myhive set dbproperties
(edited-by'='Joe');

  注意:
                設定一個屬性顯示當前所在的資料庫:
                hive>set hive.cli.print.current.db=true;

          hive會為每個資料庫建立一個目錄。資料庫中的表以資料庫的子目錄形式儲存;但default沒有目錄;
         資料庫所在目錄位於:${hive.metastore.warehouse.dir}  ;