通過執(zhí)行如下簡單的命令回車后,可以進入Hbase的shell命令行界面:
hbase shell
進入hbase命令行后,執(zhí)行help然后回車,就能看到Hbase的shell命令行下有哪些命令。下面對命令進行學(xué)習(xí)。
Command list:status,table_help,version,whoami。
hbase(main):007:0>status
1 servers,0 dead,4.0000 average load
hbase(main):009:0>table_help
Help for table-refere nce commands ......
hbase(main):012:0>version
0.98.6.1,r,Tue Apr 12 16:23:18 CST 2016
hbase(main):013:0>whoami
hbaseadmin (auth:SIMP LE)
groups: users
Command list: alter,a l t e r_a s y n c,a l t e r_status, create, describe,disable,disable_all,drop, drop_all,enable,enable_all,exists,get_table,is_disabled,is_e n a b l e d,l i s t,s h o w_filters。
hbase(main):001:0>list
TABLE
member
t1
2 row(s)i n 1.4 4 7 0 seconds
顯示某一類型的表,支持正則:
hbase(main):003:0>list "mem.*"
TABLE
member
1.創(chuàng)建student的表,含有 name、address、age列族:
create 'student','nam e','address','age'
2.創(chuàng) 建namespace為hbase并且表名為t4的表:
create 'hbase:t4',{NA ME => 'f1'}
語法:describe'tablen ame'or describe'namespac e:tablename'
注意:也可以使用縮寫的desc來查看。
查看創(chuàng)建的student表:
describe 'student'
desc 'student'
1.為student表添加nickname的列族:
alter'student',NAME=>'nickname'
2.刪除student表的nickname的列族:
alter 'student','dele te'=>'nickname'
hbase(main):003:0>enable 'student'
0 row(s) in 0.3000 seconds
hbase(main):004:0>disable 'student'
0 row(s) in 1.3610 seconds
hbase(main):005:0>drop 'student'
0 row(s) in 0.2750 seconds
hbase(main):008:0>exists 'member'
Table member does exist
hbase(main):009:0>exists 'student'
Table student does not exist
hbase(main):011:0>enable 't1'
0 row(s) in 0.0470 seconds
hbase(main):012:0>disable 't2'
0 row(s) in 1.3090 seconds
hbase(main):014:0>is_enabled 't1'
true
hbase(main):015:0>is_enabled 't2'
false
hbase(main):016:0>is_disabled 't1'
false
hbase(main):017:0>is_disabled 't2'
true
Command list:alter_n a m e s p a c e,c r e a t e_namespace,describe_namespace,drop_namespace,list_namespace,list_namespace_tables
hbase(main):026:0>list_namespace
NAMESPACE
default
hbase
2 row(s) in 0.0130 seconds
hbase(main):027:0>d e s c r i b e_n a m e s p a c e'hbase'
DESCRIPTION
{NAME => 'hbase'}
1 row(s) in 0.0180 seconds
hbase(main):029:0>list_namespace_tables'hbase'
TABLE
acl
meta
namespace
t4
4 row(s) in 0.0330 seconds
hbase(main):031:0>create_namespace 'test2'
0 row(s) in 0.0760 seconds
hbase(main):032:0>list_namespace
NAMESPACE
default
hbase
test2
3 row(s) in 0.0200 seconds
hbase(main):045:0>a l t e r_n a m e s p a c e'test2,{METHOD=>'set','P R O E R T Y_N A M E'=>'PROPERTY_VALUE'}
0 row(s) in 0.0450 seconds
hbase(main):046:0>d e s c r i b e_n a m e s p a c e'test2'
DESCRIPTION
{NAME =>'test2',PROERTY_NAME=> 'PROPERTY_VALUE'}
1 row(s) in 0.0050 seconds
hbase(main):047:0>a l t e r_n a m e s p a c e't e s t 2',{M E T H O D=>'unset',NAME=>'PROERTY_NAME'}
0 row(s) in 0.0300 seconds
hbase(main):048:0>d e s c r i b e_n a m e s p a c e'test2'
DESCRIPTION
{NAME =>'test2'}
1 row(s) in 0.0080 seconds
hbase(main):049:0>drop_namespace 'test2'
0 row(s) in 0.0990 seconds
hbase(main):050:0>list_namespace
NAMESPACE
default
hbase
2 row(s) in 0.0130 seconds
Command list:append,count,delete,deleteall,get,get_counter,incr,p u t,s c a n,t r u n c a t e,truncate_preserve
添加rowkey為rowkey00 1記錄:
put'student','rowkey0 01','address:colum1','ji axi'
put 'student','rowkey 001','age:colum1','100'
查 詢studen表 中rowkey為rowkey001的記錄:get 'student','rowkey 001'
查 詢student表 中rowkey為 rowkey001,并 且列族age為colum1的記錄:
get 'student','rowkey 001','age:colum1'
全表掃描student的數(shù)據(jù):
scan 'student'
只掃描stdent的前2行記錄:
scan 'student',{LIMIT=> 2}
查看student表的記錄數(shù):
count 'student'
刪 除s t u d e n t中rowkey001為aget:colum1的值:
delete 'student','row key001','age:colum1'
刪除整行的數(shù)據(jù):
deleteall'student','rowkey001'
刪除整個表的數(shù)據(jù):
truncate'student'