表操作命令:
- 创建表:
create 'table_name', 'column_family1', 'column_family2', ...示例:create 'my_table', 'cf1', 'cf2' - 禁用表:
disable 'table_name'禁用表后,该表将不再接受读写操作。 - 启用表:
enable 'table_name'启用之前禁用的表。 - 修改表结构:
alter 'table_name', {NAME => 'new_column_family', VERSIONS => 3}示例:alter 'my_table', {NAME => 'new_cf', VERSIONS => 5}修改表结构,如增加新的列族或修改列族的版本数。 - 查看表描述:
describe 'table_name'显示表的详细信息,包括列族、配置选项等。 - 列出所有表:
list列出当前 HBase 实例中所有的表。
数据操作命令:
- 插入或更新数据:
put 'table_name', 'row_key', 'column_family:column', 'value'示例:put 'my_table', 'row1', 'cf1:col1', 'value1' - 获取数据:
get 'table_name', 'row_key'示例:get 'my_table', 'row1'获取指定行的数据。 - 删除数据:
delete 'table_name', 'row_key', 'column_family:column', 'timestamp'示例:delete 'my_table', 'row1', 'cf1:col1', 1597101234567删除指定行或指定列的数据,可以指定时间戳(timestamp)。 - 扫描表:
scan 'table_name'示例:scan 'my_table'扫描整个表的数据。看表最后一行是scan 'my_table',{REVERSED => true,LIMIT =>1}
其他操作命令:
- 查看集群状态:
status显示 HBase 集群的状态信息,包括活动的 RegionServers、负载情况等。 - 查看 HBase 版本:
version显示当前 HBase 的版本信息。 - 统计表中的行数:
count 'table_name'示例:count 'my_table'统计表中的行数。 - 清空表中的所有数据:
truncate 'table_name'示例:truncate 'my_table'清空指定表中的所有数据,表结构保持不变。