Hive 对数据库的基本操作(一)

Hive对数据库的操作,基本上与MySql一致。


一,对数据库进行操作

1,查看所有数据库

hive> show databases;

2,创建新数据库

hive> create database dataBaseName;

也可以对创建的数据库加上判断,比如不确定这个数据库是否存在,就可以用以下语句来创建

hive> create database dataBaseName if not exist;

3,删除数据库

删除空数据库

hive> drop database dataBaseName;

删除有数据的数据库

hive> drop database dataBaseName cascade;

4,使用数据库

hive> use database dataBaseName;

5,查看数据库信息

hive> desc database dataBaseName;

二,对表进行操作

1,查看当前库中的所有表

hive> show tables;

2,创建新表

给定表名 tableName,字段名field,字段类型type,格式化数据行:用,分割字段,用回车分割行,stored类型为文本文件。若规定没有格式化分割行,则使用hive默认的分隔符。

hive> create table tableName(field type,field type,...)
 row format delimited
 fields terminated by ','
 lines terminated by '\n'
 stored as textfile;

3,删除表

hive> drop table tableName;

4,查看表结构

查看表的数据结构

hive> desc tableName;

查看表的结构的扩展信息

hive> desc extended tableName;

 5,更改表结构

更改表名

hive> alter table tableName rename to newTableName;

 更改字段名

hive> alter table tableName change column field newfield type;

增加字段

hive> alter table tableName add columns(field type,field type,...);

  • 4
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值