通过执行如下简单的命令回车后,可以进入Hbase的shell命令行界面:
hbase shell
进入hbase命令行后,执行help然后回车,就能看到Hbase的shell命令行下有哪些命令。下面对命令进行学习。
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.创建student的表,含有 name、address、age列族:
create 'student','nam e','address','age'
2.创 建namespace为hbase并且表名为t4的表:
create 'hbase:t4',{NA ME => 'f1'}
语法:describe'tablen ame'or describe'namespac e:tablename'
注意:也可以使用缩写的desc来查看。
查看创建的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的数据:
scan 'student'
只扫描stdent的前2行记录:
scan 'student',{LIMIT=> 2}
查看student表的记录数:
count 'student'
删 除s t u d e n t中rowkey001为aget:colum1的值:
delete 'student','row key001','age:colum1'
删除整行的数据:
deleteall'student','rowkey001'
删除整个表的数据:
truncate'student'