常用命令
進(jìn)入hbase命令行
./hbase shell
顯示hbase中的表
list
創(chuàng)建user表哲身,包含info陶舞、data兩個(gè)列族
create 'user', 'info1', 'data1'
create 'user', {NAME => 'info', VERSIONS => '3'}
向user表中插入信息,row key為rk0001,列族info中添加name列標(biāo)示符周霉,值為zhangsan
put 'user', 'rk0001', 'info:name', 'zhangsan'
向user表中插入信息,row key為rk0001,列族info中添加gender列標(biāo)示符这橙,值為female
put 'user', 'rk0001', 'info:gender', 'female'
向user表中插入信息,row key為rk0001导披,列族info中添加age列標(biāo)示符屈扎,值為20
put 'user', 'rk0001', 'info:age', 20
向user表中插入信息,row key為rk0001撩匕,列族data中添加pic列標(biāo)示符鹰晨,值為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列標(biāo)示符的信息
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棚潦,版本號(hào)最新5個(gè)的信息
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膝昆,列標(biāo)示符中含有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', '中國(guó)'
get 'user', 'rk0002', {FILTER => "ValueFilter(=, 'binary:中國(guó)')"}
查詢(xún)user表中的所有信息
scan 'user'
查詢(xún)user表中列族為info的信息
scan 'user', {COLUMNS => 'info'}
scan 'user', {COLUMNS => 'info', RAW => true, VERSIONS => 5}
scan 'persion', {COLUMNS => 'info', RAW => true, VERSIONS => 3}
查詢(xún)user表中列族為info和data的信息
scan 'user', {COLUMNS => ['info', 'data']}
scan 'user', {COLUMNS => ['info:name', 'data:pic']}
查詢(xún)user表中列族為info、列標(biāo)示符為name的信息
scan 'user', {COLUMNS => 'info:name'}
查詢(xún)user表中列族為info叠必、列標(biāo)示符為name的信息,并且版本最新的5個(gè)
scan 'user', {COLUMNS => 'info:name', VERSIONS => 5}
查詢(xún)user表中列族為info和data且列標(biāo)示符中含有a字符的信息
scan 'user', {COLUMNS => ['info', 'data'], FILTER => "(QualifierFilter(=,'substring:a'))"}
查詢(xún)user表中列族為info荚孵,rk范圍是[rk0001, rk0003)的數(shù)據(jù)
scan 'people', {COLUMNS => 'info', STARTROW => 'rk0001', ENDROW => 'rk0003'}
查詢(xún)user表中row key以rk字符開(kāi)頭的
scan 'user',{FILTER=>"PrefixFilter('rk')"}
查詢(xún)user表中指定范圍的數(shù)據(jù)
scan 'user', {TIMERANGE => [1392368783980, 1392380169184]}
刪除數(shù)據(jù)
刪除user表row key為rk0001,列標(biāo)示符為info:name的數(shù)據(jù)
delete 'people', 'rk0001', 'info:name'
刪除user表row key為rk0001纬朝,列標(biāo)示符為info:name收叶,timestamp為1392383705316的數(shù)據(jù)
delete 'user', 'rk0001', 'info:name', 1392383705316
清空user表中的數(shù)據(jù)
truncate 'people'
修改表結(jié)構(gòu)
首先停用user表(新版本不用)
disable 'user'
添加兩個(gè)列族f1和f2
alter 'people', NAME => 'f1'
alter 'user', NAME => 'f2'
啟用表
enable 'user'
###disable 'user'(新版本不用)
刪除一個(gè)列族:
alter 'user', NAME => 'f1', METHOD => 'delete' 或 alter 'user', 'delete' => 'f1'
添加列族f1同時(shí)刪除列族f2
alter 'user', {NAME => 'f1'}, {NAME => 'f2', METHOD => 'delete'}
將user表的f1列族版本號(hào)改為5
alter 'people', NAME => 'info', VERSIONS => 5
啟用表
enable 'user'
刪除表
disable 'user'
drop 'user'
get 'person', 'rk0001', {FILTER => "ValueFilter(=, 'binary:中國(guó)')"}
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']}