hbase shell操作語句
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
向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‘
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: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‘]}
hbase shell操作語句