Hive基础操作
更新时间:2025-01-23
本文介绍如何通过 Hive 在 BMR 集群上进行库、表操作
前提条件
- 已创建 BMR 集群,且选择了 Hive 服务,创建集群详情请参见创建集群。
库操作
注意:示例中的数据库名称以testdb为例介绍。
- 创建库
Plain Text
1create database if not exists testdb;
当返回信息包含OK时,表示创建库testdb成功。
- 查看库
Plain Text
1desc database testdb;
- 使用数据库
Plain Text
1use testdb;
- 删除库
Plain Text
1drop database if exists testdb;
当返回信息包含OK时,表示删除库成功。
表操作
注意:示例中的数据表名称以t为例介绍。
- 创建表
Plain Text
1create table if not exists t (id bigint, value string);
当返回信息包含OK时,表示创建表table成功。
- 查看表信息
Plain Text
1desc formatted t;
- 查看所有表
Plain Text
1show tables;
返回信息如下所示:
Plain Text
1OK
2t
- 删除表
Plain Text
1drop table if exists t;
当返回信息包含OK时,表示删除表成功。
SQL操作
- 插入记录
Plain Text
1insert into table t select 1, 'value-1';
当返回信息包含OK时,表示插入信息成功。
- 查询表中的信息
Plain Text
1select * from t limit 10;
- 聚合操作
Plain Text
1select value, count(id) from t group by value;