默認數據庫"default"
可以顯式切換數據庫:hive> use 數據庫名;
創建
hive>CREATE DATABASE ?[IF NOT EXISTS] mydb ?
[LOCATION] '/.......' ?
[COMMENT] '....';
實例
hive (default)> create database test_db comment 'test database';
OK
Time taken: 0.33 seconds
hive (default)> create database if not exists test_db comment 'test database';
OK
Time taken: 0.013 seconds
hive (default)> create database if not exists test2_dblocation'/home/hive2.1/test_database';
OK
Time taken: 0.054 seconds
注意:location 不是linux的文件系統,是hdfs的。location是指定目錄,
如果不指定會默認放到/user/hive/warehouse 下。下面查看可知。
hive (test2_db)> describe database test2_db;
OK
db_name comment location ? ? ? ?owner_name ? ? ?owner_type ? ? ?parameters
test2_db ? ? ? ? ? ? ? ?hdfs://hello110:9000/home/hive2.1/test_database hadoop ?USER
Linux文件系統里沒有
[hadoop@hello110 test_database]$ pwd
/home/hive2.1/test_database
[hadoop@hello110 test_database]$ ll
total 0
顯示
hive>SHOW DATABASES;描述
hive>DESCRIBE DATABASE [extended] mydb;刪除
hive>DROP DATABASE [IF EXISTS] mydb [CASCADE];
實例
hive (test2_db)> drop database test2_db;
FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. InvalidOperationException(message:Database test2_db is not empty. One or more tables exist.)
cascade關鍵字,強制刪除,hive會把文件移動hdfs回收站
hive (test2_db)> drop database test2_db cascade;
Moved: 'hdfs://hello110:9000/home/hive2.1/test_database/t1' to trash at: hdfs://hello110:9000/user/hadoop/.Trash/Current
Moved: 'hdfs://hello110:9000/home/hive2.1/test_database' to trash at: hdfs://hello110:9000/user/hadoop/.Trash/Current
OK
Time taken: 1.384 seconds
hive (test2_db)>?