hbase安装部署完成后,如果已经设置了hbase的环境变量(如HBASE_HOME=/home/david/cloudera/lib/hbase-1.2.5),则直接在命令行窗口下,执行命令:hbase shell,呼起shell环境。
HBase Shell; enter ‘help’ for list of supported commands.
Type “exit” to leave the HBase Shell
Version 1.2.5, rd7b05f79dee10e0ada614765bb354b93d615a157, Wed Mar 1 00:34:48 CST 2017hbase(main):001:0>
接着执行help命令,则hbase将按group形式,分组列出所有该组下的命令。
分组名 | 命令名 |
---|---|
general | status, table_help, version, whoami |
ddl | alter, alter_async, alter_status, create, describe, disable, disable_all, drop, drop_all, enable, enable_all, exists, get_table, is_disabled, is_enabled, list, locate_region, show_filters |
namespace | alter_namespace, create_namespace, describe_namespace, drop_namespace, list_namespace, list_namespace_tables |
dml | append, count, delete, deleteall, get, get_counter, get_splits, incr, put, scan, truncate, truncate_preserve |
tools | assign, balance_switch, balancer, balancer_enabled, catalogjanitor_enabled, catalogjanitor_run, catalogjanitor_switch, close_region, compact, compact_rs, flush, major_compact, merge_region, move, normalize, normalizer_enabled, normalizer_switch, split, trace, unassign, wal_roll, zk_dump |
replication | add_peer, append_peer_tableCFs, disable_peer, disable_table_replication, enable_peer, enable_table_replication, list_peers, list_replicated_tables, remove_peer, remove_peer_tableCFs, set_peer_tableCFs, show_peer_tableCFs |
snapshots | clone_snapshot, delete_all_snapshot, delete_snapshot, list_snapshots, restore_snapshot, snapshot |
configuration | update_all_config, update_config |
quotas | list_quotas, set_quota |
security | grant, list_security_capabilities, revoke, user_permission |
procedures | abort_procedure, list_procedures |
visibility labels | add_labels, clear_auths, get_auths, list_labels, set_auths, set_visibility |
常用命令如下
命令作用 | 表达式 | |
---|---|---|
一。表的管理 | ① 查看表的列表 | list |
② 建表 | create ‘表名’,’列簇1’,’列簇2’,…,’列簇N’ | |
③ 查看表结构 | describe ‘表名’ | |
④ 修改表结构,删除表的某个列簇 | 1. disable ‘表名’; 2.alter ‘表名’, {NAME=>’列簇名’,METHOD=>’delete’} | |
⑤ 删表 | 1. disable ‘表名’; 2.drop ‘表名’;enable ‘表名’ | |
二。权限管理 | ① 分配权限 | grant ‘用户名’,’权限’,’表名’ |
② 查看权限 | user_permission ‘表名’ | |
③ 收回权限 | revoke ‘用户名’,’表名’ | |
三。表的CURD | ① 添加记录 | put ‘表名’,’行名’,’列簇名:列名’,’值’ |
②查询数据 a).查看rowKey全部列簇的记录 | get ‘表名’,’行名’ | |
b).查看rowKey某一列簇的记录 | get ‘表名’,’行名’,’列簇名’ | |
c).查看rowKey某一列簇的某一列记录 | get ‘表名’,’行名’,’列簇名:列名’ | |
扫描表 a).扫描全表记录 | scan ‘member’ | |
b).扫描全表前N条记录 | scan ‘member’, {LIMIT=>3} | |
查看表记录行数 | count ‘表名’ | |
③ 删除记录 a).删除行中某一列 | delete ‘表名’,’行名’,’列簇名:列名’ | |
b).删除行 | deleteall ‘表名’,’行名’ | |
c).删除表中全部数据 | truncate ‘表名’ | |
四。Region管理 | ① 移动region | move ‘encodeRegionName’, ‘ServerName’ |
② 开启/关闭region | balance_switch (true|false) | |
③ 手动split | split ‘regionName’, ‘splitKey’ | |
④ 手动触发major compaction | #语法:#Compact all regions in a table:#hbase> major_compact ‘t1’#Compact an entire region:#hbase> major_compact ‘r1’#Compact a single column family within a region:#hbase> major_compact ‘r1’, ‘c1’#Compact a single column family within a table:#hbase> major_compact ‘t1’, ‘c1’ |