HBase Shell的所有命令可分为6大组
常规命令
DDL命令
DML命令
工具命令(Tools)
复制(Replication)
安全(Security)
HBase Shell 命令 – 常规命令
集群状态命令status
2 servers, 0 dead, 2.5000 average load
该集群共有两台RegionServer,平均每台上有2.5个region
HBase版本命令version
0.98.9-hadoop2, r96878ece501b0643e879254645d7f3a40eaf101f, Mon Dec 15 23:00:20 PST 2014
版本号,版本修订号,编译HBase的时间
HBase Shell 命令 – DDL命令
DDL命令,即数据定义语言命令,包括的命令有创建表、修改表、上线和下线表、删除表、罗列表等操作。
create 创建表 member,指定三个列族
create ‘member’, ‘member_id’, ‘address’, ‘info’
list 罗列表
describe 查看表信息
describe ‘member’
disable 下线某个表
disable ‘member’
enable 上线某个表
enable ‘member’
exists 判断表是否存在
exists ‘member’
is_enabled 判断表是否上线
is_enabled ‘member’
is_disabled 判断表是否下线
Id
drop 删除表
disable ‘member’
drop ‘member’
alter 修改表的列族的描述属性
删除列族:disable、enable、 alter
describe ‘member’
disable ‘member’
alter ‘member’, {NAME=> ‘f1’,METHOD=>‘delete’}
Alter ‘member’,{NAME=>’f2’}
alter ‘member’, ‘delete’=> ‘info’
Alter ‘member’, NAME=>’f3’
enable ‘member’
describe ‘member’
HBase Shell 命令 – DML命令
DML命令,即数据操纵语言命令,用于数据的写入、删除、查询、清空等操作
put 数据写入
put ‘member’, ‘xueba’, ‘info:age’, ‘25’
put ‘member’, ‘xueba’, ‘info:birthday’, ‘1989-09-08’
put ‘member’, ‘xueba’, ‘info:company’, ‘tecent’
put ‘member’, ‘xueba’, ‘address:contry’, ‘china’
put ‘member’, ‘xueba’, ‘address:province’, ‘guangdong’
put ‘member’, ‘xueba’, ‘address:city’, ‘shenzhen’
Put ‘member’, ‘xiaoming’, ‘info:age’, ‘24’
put ‘member’, ‘xiaoming’, ‘info:birthday’, ‘1990-03-28’
put ‘member’, ‘xiaoming’, ‘info:company’, ‘tecent’
Put ‘member’, ‘xiaoming’, ‘info:favorite’, ‘movie’
put ‘member’, ‘xiaoming’, ‘address:contry’, ‘china’
put ‘member’, ‘xiaoming’, ‘address:province’, ‘guangdong’
put ‘member’, ‘xiaoming’, ‘address:city’, ‘shenzhen’
Put 更新记录
Put ‘member’, ‘xueba’, ‘info:age’, ‘26’
get 单行读
get ‘member’, ‘xueba’
get ‘member’, ‘xiaoming’, ‘info’
get ‘member’, ‘xueba’, ‘info:age’
通过 timestamp 来获取数据
get ‘member’, ‘xueba’, {COLUMN=> ‘info:age’, TIMESTAMP=>124321423124}
scan 扫描读
scan ‘member’
scan 'member',{COLUMNS=>'info:birthday'}
delete 删除一个单元格
delete ‘member’, ‘xueba’, ‘info:age’
get ‘member’, ‘xueba’
deleteall 删除整行
deleteall ‘member’, ‘xiaoming’
删除一个列簇
alter ‘member’, {NAME=> ‘f1’,METHOD=>‘delete’}
alter ‘member’, ‘delete’=> ‘info’
get ‘member’, ‘xiaoming’
count 查询表中有多少行
count ‘member’
truncate 清空表
truncate ‘member’
HBase Shell 命令 – 工具命令
balance_switch 启用或关闭负载均衡器,返回结果是当前均衡器状态
balance_switch true balance_switch false
compact 合并表或Region
compact ‘t1’ compact ‘t1’, ‘c1’
major_compact 大合并表或Region
major_compact ‘t1’ major_compact ‘t1’, ‘c1’
split 分列表或Region
split ‘tableName’
修改一个列簇可以保存的版本数
alter 'customer',{NAME=>'info',VERSIONS=>3}