利用hbase shell 创建表
时间: 2023-10-02 16:04:43 浏览: 104
可以使用以下命令在 HBase Shell 中创建表:
```
create 'my_table', 'cf1', 'cf2'
```
这将创建一个名为 `my_table` 的表,并为其指定两个列族:`cf1` 和 `cf2`。
如果要在创建表时指定更多的选项,可以使用以下命令:
```
create 'my_table', {NAME => 'cf1', VERSIONS => 1}, {NAME => 'cf2', VERSIONS => 5}, {NAME => 'cf3'}
```
这将创建一个名为 `my_table` 的表,并为其指定三个列族:`cf1`、`cf2` 和 `cf3`。`cf1` 只保留一个版本,`cf2` 保留五个版本,而 `cf3` 使用默认的版本数(通常为 1)。
还可以为表添加配置选项,例如:
```
create 'my_table', 'cf1', 'cf2', {SPLITS => ['10', '20']}
```
这将创建一个名为 `my_table` 的表,并为其指定两个列族:`cf1` 和 `cf2`。此外,它还将表分为三个区域,其中第一个区域包含行键小于 10 的行,第二个区域包含行键在 10 和 20 之间的行,第三个区域包含行键大于 20 的行。
相关问题
如何在hbase里面创建表
### 如何在HBase中创建表
要在HBase中创建表,通常通过HBase Shell命令行工具完成。以下是具体操作方法:
#### 使用HBase Shell 创建表
启动HBase之后,在终端输入`hbase shell`进入交互环境[^1]。
```shell
hbase(main):001:0> create 'test', 'cf'
```
上述命令会创建一张名为 `test` 的新表,并定义了一个列族 `cf` 。每张HBase表至少要有一个列族(column family),而列名由该列族前缀加上冒号以及限定符组成[^2]。
对于更复杂的场景,比如指定预分区键(pre-split keys) 或者设置其他参数如最大版本数(max_versions), 可以采用如下方式构建表格:
```shell
hbase(main):002:0> create 'big_table', {NAME => 'info', VERSIONS => 5}, SPLITS_FILE=>'splits.txt'
```
这里`splits.txt` 文件包含了用于初始化分割区域(region)的一系列键值列表,每一行代表一个键。
除了CLI外,还可以利用Java API或者其他支持的语言绑定(例如Python, PHP等)编程接口实现相同功能。这些高级特性允许开发者更加灵活地管理集群资源并优化性能表现。
利用Shell命令完成下列操作。 1.在HBase中创建一个客户表,名为customer,列族名为info,最大版本数为3。 2.将customer表info 列族的TTL改为30天。 3.向customer表中插入一行数据(cust101,2020-05-04,124.64.242.30,1),各字段分别表示D (rowkey)、注册日期(reg_ date)、IP地址(reg_ip)和状态(reg_status)。 4.查询ID为cust101的客户的注册日期。 5.查询D为cust101的客户的所有信息。
1. 创建客户表customer
```
hbase shell
create 'customer', 'info', {VERSIONS => 3}
```
2. 修改info列族TTL为30天
```
alter 'customer', NAME => 'info', TTL => '2592000'
```
3. 向customer表中插入一行数据
```
put 'customer', 'cust101', 'info:reg_date', '2020-05-04'
put 'customer', 'cust101', 'info:reg_ip', '124.64.242.30'
put 'customer', 'cust101', 'info:reg_status', '1'
```
4. 查询ID为cust101的客户的注册日期
```
get 'customer', 'cust101', {COLUMN => 'info:reg_date'}
```
5. 查询D为cust101的客户的所有信息
```
get 'customer', 'cust101'
```
阅读全文
相关推荐















