hive数据库定义


默认数据库"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)> 



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

松门一枝花

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值