在学习Hbase的shell命令,之前先得了解如何进入hbase的shell命令行,通过执行如下简单的命令回车后进入hbase的shell命令行界面
hbase shell
进入hbase命令行后,执行help然后回车,就能看到Hbase的shell命令行下有哪些命令,下面是根据help反馈的几类命令来进行学习:
一、 general commands
Command list: status, table_help, version, whoami
1、查看整理的状态
hbase(main):007:0> status
1 servers, 0 dead, 4.0000 average load
2、查看表涉及的命令对应的帮助
hbase(main):009:0> table_help
Help for table-reference commands ……
3、查看Hbase版本
hbase(main):012:0> version
0.98.6.1, r, Tue Apr 12 16:23:18 CST 2016
4、查看当前用户
hbase(main):013:0> whoami
hbaseadmin (auth:SIMPLE)
groups: users
二、ddl commands
Command list: alter, alter_async, alter_status, create, describe, disable, disable_all, drop, drop_all, enable, enable_all, exists, get_table, is_disabled, is_enabled, list, show_filters
1、显式所有的表
hbase(main):001:0> list
TABLE
member
t1
2 row(s) in 1.4470 seconds
显式某一类型的表,支持正则
hbase(main):003:0> list “mem.*”
TABLE
member
2、创建表(create)
2.1 创建student的表,含有name、address、age列族
create ‘student’,’name’,’address’,’age’
2.2 创建namespace为hbase并且表名为t4的表
create ‘hbase:t4’,{NAME => ‘f1’}
3、查看表(describe)
语法: describe ‘tablename’ or describe ‘namespace:tablename’
备注:也可以使用缩写的desc来查看
3.1 查看创建的student表
describe ‘student’
desc ‘student’
4、修改表(alter)
4.1 为student表添加nickname的列族
alter ‘student’,NAME => ‘nickname’
4.2 删除student表的nickname的列族
alter ‘student’,’delete’ => ‘nickname’
5、启用表(enable)
hbase(main):003:0> enable ‘student’
0 row(s) in 0.3000 seconds
6、禁用表(disable)
hbase(main):004:0> disable ‘student’
0 row(s) in 1.3610 seconds
7、删除表(drop)
hbase(main):005:0> drop ‘student’
0 row(s) in 0.2750 seconds
8、判断表是否存在(exists
hbase(main):008:0> exists ‘member’
Table member does exist
hbase(main):009:0> exists ‘student’
Table student does not exist
9、判断表是否启用(is_enabled)
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
10、判断表是否禁用(is_disabled)
hbase(main):016:0> is_disabled ‘t1’
false
hbase(main):017:0> is_disabled ‘t2’
true
三、 namespace commands
Command list: alter_namespace, create_namespace, describe_namespace, drop_namespace, list_namespace, list_namespace_tables
1、查看表空间列表
hbase(main):026:0> list_namespace
NAMESPACE
default
hbase
2 row(s) in 0.0130 seconds
2、查看表空间
hbase(main):027:0> describe_namespace ‘hbase’
DESCRIPTION
{NAME => ‘hbase’}
1 row(s) in 0.0180 seconds
3、查看表空间的表
hbase(main):029:0> list_namespace_tables ‘hbase’
TABLE
acl
meta
namespace
t4
4 row(s) in 0.0330 seconds
4、创建表空间
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
5、修改表空间
hbase(main):045:0> alter_namespace ‘test2’,{METHOD => ‘set’, ‘PROERTY_NAME’ => ‘PROPERTY_VALUE’}
0 row(s) in 0.0450 seconds
hbase(main):046:0> describe_namespace ‘test2’
DESCRIPTION
{NAME => ‘test2’, PROERTY_NAME => ‘PROPERTY_VALUE’}
1 row(s) in 0.0050 seconds
hbase(main):047:0> alter_namespace ‘test2’,{METHOD => ‘unset’, NAME=>’PROERTY_NAME’}
0 row(s) in 0.0300 seconds
hbase(main):048:0> describe_namespace ‘test2’
DESCRIPTION
{NAME => ‘test2’}
1 row(s) in 0.0080 seconds
6、删除表空间
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
四、dml commands
Command list: append, count, delete, deleteall, get, get_counter, incr, put, scan, truncate, truncate_preserve
1、添加记录
添加rowkey为rowkey001记录
put ‘student’,’rowkey001′,’address:colum1′,’jiaxi’
put ‘student’,’rowkey001′,’age:colum1′,’100′
2、查询记录
查询studen表中rowkey为rowkey001的记录
get ‘student’,’rowkey001′
查询student表中rowkey为rowkey001,并且列族age为colum1的记录
get ‘student’,’rowkey001′,’age:colum1′
3、扫描表
全表扫描student的数据
scan ‘student’
只扫描stdent的前2行记录
scan ‘student’,{LIMIT => 2}
4、查看表的记录数
查看student表的记录数
count ‘student’
5、删除记录
删除student中rowkey001为aget:colum1的值
delete ‘student’,’rowkey001′,’age:colum1′
删除整行的数据
deleteall ‘student’,’rowkey001′
删除整个表的数据
truncate ‘student’