2019/2/19 星期二
hbase shell操作语句
基本shell 命令
进入hbase 命令行
./hbase shell
显示hbase 中的表
list
创建user 表,包含info、data 两个列族
create ‘user‘, ‘info1‘, ‘data1‘
create ‘user‘, {NAME => ‘info‘, VERSIONS => ‘3‘}
向user 表中插入信息,row key 为rk0001,列族info 中添加name 列标示符,值为zhangsan
put ‘user‘, ‘rk0001‘, ‘info:name‘, ‘zhangsan‘
向user 表中插入信息,row key 为rk0001,列族info 中添加gender 列标示符,值为female
put ‘user‘, ‘rk0001‘, ‘info:gender‘, ‘female‘
向user 表中插入信息,row key 为rk0001,列族info 中添加age 列标示符,值为20
put ‘user‘, ‘rk0001‘, ‘info:age‘, 20
向user 表中插入信息,row key 为rk0001,列族data 中添加pic 列标示符,值为picture
put ‘user‘, ‘rk0001‘, ‘data:pic‘, ‘picture‘
获取user 表中row key 为rk0001 的所有信息
get ‘user‘, ‘rk0001‘
获取user 表中row key 为rk0001,info 列族的所有信息
get ‘user‘, ‘rk0001‘, ‘info‘
获取user 表中row key 为rk0001,info 列族的name、age 列标示符的信息
get ‘user‘, ‘rk0001‘, ‘info:name‘, ‘info:age‘
获取user 表中row key 为rk0001,info、data 列族的信息
get ‘user‘, ‘rk0001‘, ‘info‘, ‘data‘
get ‘user‘, ‘rk0001‘, {COLUMN => [‘info‘, ‘data‘]}
get ‘user‘, ‘rk0001‘, {COLUMN => [‘info:name‘, ‘data:pic‘]}
获取user 表中row key 为rk0001,列族为info,版本号最新5 个的信息
get ‘user‘, ‘rk0001‘, {COLUMN => ‘info‘, VERSIONS => 2}
get ‘user‘, ‘rk0001‘, {COLUMN => ‘info:name‘, VERSIONS => 5}
get ‘user‘, ‘rk0001‘, {COLUMN => ‘info:name‘, VERSIONS => 5, TIMERANGE =>[1392368783980, 1392380169184]}
获取user 表中row key 为rk0001,cell 的值为zhangsan 的信息
get ‘people‘, ‘rk0001‘, {FILTER => "ValueFilter(=, ‘binary:图片‘)"}
获取user 表中row key 为rk0001,列标示符中含有a 的信息
get ‘people‘, ‘rk0001‘, {FILTER => "(QualifierFilter(=,‘substring:a‘))"}
put ‘user‘, ‘rk0002‘, ‘info:name‘, ‘fanbingbing‘
put ‘user‘, ‘rk0002‘, ‘info:gender‘, ‘female‘
put ‘user‘, ‘rk0002‘, ‘info:nationality‘, ‘中国‘
get ‘user‘, ‘rk0002‘, {FILTER => "ValueFilter(=, ‘binary:中国‘)"}
查询user 表中的所有信息
scan ‘user‘
查询user 表中列族为info 的信息
scan ‘user‘, {COLUMNS => ‘info‘}
scan ‘user‘, {COLUMNS => ‘info‘, RAW => true, VERSIONS => 5}
scan ‘persion‘, {COLUMNS => ‘info‘, RAW => true, VERSIONS => 3}
查询user 表中列族为info 和data 的信息
scan ‘user‘, {COLUMNS => [‘info‘, ‘data‘]}
scan ‘user‘, {COLUMNS => [‘info:name‘, ‘data:pic‘]}
查询user 表中列族为info、列标示符为name 的信息
scan ‘user‘, {COLUMNS => ‘info:name‘}
查询user 表中列族为info、列标示符为name 的信息,并且版本最新的5 个
scan ‘user‘, {COLUMNS => ‘info:name‘, VERSIONS => 5}
查询user 表中列族为info 和data 且列标示符中含有a 字符的信息
scan ‘user‘, {COLUMNS => [‘info‘, ‘data‘], FILTER => "(QualifierFilter(=,‘substring:a‘))"}
查询user 表中列族为info,rk 范围是[rk0001, rk0003)的数据
scan ‘people‘, {COLUMNS => ‘info‘, STARTROW => ‘rk0001‘, ENDROW => ‘rk0003‘}
查询user 表中row key 以rk 字符开头的
scan ‘user‘,{FILTER=>"PrefixFilter(‘rk‘)"}
查询user 表中指定范围的数据
scan ‘user‘, {TIMERANGE => [1392368783980, 1392380169184]}
删除数据
删除user 表row key 为rk0001,列标示符为info:name 的数据
delete ‘people‘, ‘rk0001‘, ‘info:name‘
删除user 表row key 为rk0001,列标示符为info:name,timestamp 为1392383705316 的数据
delete ‘user‘, ‘rk0001‘, ‘info:name‘, 1392383705316
清空user 表中的数据
truncate ‘people‘
修改表结构
首先停用user 表(新版本不用)
disable ‘user‘
添加两个列族f1 和f2
alter ‘people‘, NAME => ‘f1‘
alter ‘user‘, NAME => ‘f2‘
启用表
enable ‘user‘
###disable ‘user‘(新版本不用)
删除一个列族:
alter ‘user‘, NAME => ‘f1‘, METHOD => ‘delete‘ 或alter ‘user‘, ‘delete‘ => ‘f1‘
添加列族f1 同时删除列族f2
alter ‘user‘, {NAME => ‘f1‘}, {NAME => ‘f2‘, METHOD => ‘delete‘}
将user 表的f1 列族版本号改为5
alter ‘people‘, NAME => ‘info‘, VERSIONS => 5
启用表
enable ‘user‘
删除表
disable ‘user‘
drop ‘user‘
get ‘person‘, ‘rk0001‘, {FILTER => "ValueFilter(=, ‘binary:中国‘)"}
get ‘person‘, ‘rk0001‘, {FILTER => "(QualifierFilter(=,‘substring:a‘))"}
scan ‘person‘, {COLUMNS => ‘info:name‘}
scan ‘person‘, {COLUMNS => [‘info‘, ‘data‘], FILTER => "(QualifierFilter(=,‘substring:a‘))"}
scan ‘person‘, {COLUMNS => ‘info‘, STARTROW => ‘rk0001‘, ENDROW => ‘rk0003‘}
scan ‘person‘, {COLUMNS => ‘info‘, STARTROW => ‘20140201‘, ENDROW => ‘20140301‘}
scan ‘person‘, {COLUMNS => ‘info:name‘, TIMERANGE => [1395978233636,
1395987769587]}
delete ‘person‘, ‘rk0001‘, ‘info:name‘
alter ‘person‘, NAME => ‘ffff‘
alter ‘person‘, NAME => ‘info‘, VERSIONS => 10
get ‘user‘, ‘rk0002‘, {COLUMN => [‘info:name‘, ‘data:pic‘]}
原文地址:http://blog.51cto.com/12445535/2351976