在學習Hbase的shell命令,以前先得了解如何進入hbase的shell命令行,經過執行以下簡單的命令回車後進入hbase的shell命令行界面shell
hbase shellapp
進入hbase命令行後,執行help而後回車,就能看到Hbase的shell命令行下有哪些命令,下面是根據help反饋的幾類命令來進行學習:async
1、 general commands學習
Command list: status, table_help, version, whoamispa
一、查看整理的狀態命令行
hbase(main):007:0> statusserver
1 servers, 0 dead, 4.0000 average loadget
二、查看錶涉及的命令對應的幫助io
hbase(main):009:0> table_helptable
Help for table-reference commands ......
三、查看Hbase版本
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:SIMPLE)
groups: users
2、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
一、顯式全部的表
hbase(main):001:0> list
TABLE
member
t1
2 row(s) in 1.4470 seconds
顯式某一類型的表,支持正則
hbase(main):003:0> list "mem.*"
TABLE
member
二、建立表(create)
2.1 建立student的表,含有name、address、age列族
create 'student','name','address','age'
2.2 建立namespace爲hbase而且表名爲t4的表
create 'hbase:t4',{NAME => 'f1'}
三、查看錶(describe)
語法: describe 'tablename' or describe 'namespace:tablename'
備註:也可使用縮寫的desc來查看
3.1 查看建立的student表
describe 'student'
desc 'student'
四、修改表(alter)
4.1 爲student表添加nickname的列族
alter 'student',NAME => 'nickname'
4.2 刪除student表的nickname的列族
alter 'student','delete' => 'nickname'
五、啓用表(enable)
hbase(main):003:0> enable 'student'
0 row(s) in 0.3000 seconds
六、禁用表(disable)
hbase(main):004:0> disable 'student'
0 row(s) in 1.3610 seconds
七、刪除表(drop)
hbase(main):005:0> drop 'student'
0 row(s) in 0.2750 seconds
八、判斷表是否存在(exists
hbase(main):008:0> exists 'member'
Table member does exist
hbase(main):009:0> exists 'student'
Table student does not exist
九、判斷表是否啓用(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
十、判斷表是否禁用(is_disabled)
hbase(main):016:0> is_disabled 't1'
false
hbase(main):017:0> is_disabled 't2'
true
3、 namespace commands
Command list: alter_namespace, create_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> describe_namespace '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> 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
六、刪除表空間
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
4、dml commands
Command list: append, count, delete, deleteall, get, get_counter, incr, put, scan, truncate, truncate_preserve
一、添加記錄
添加rowkey爲rowkey001記錄
put 'student','rowkey001','address:colum1','jiaxi'
put 'student','rowkey001','age:colum1','100'
二、查詢記錄
查詢studen表中rowkey爲rowkey001的記錄
get 'student','rowkey001'
查詢student表中rowkey爲rowkey001,而且列族age爲colum1的記錄
get 'student','rowkey001','age:colum1'
三、掃描表
全表掃描student的數據
scan 'student'
只掃描stdent的前2行記錄
scan 'student',{LIMIT => 2}
四、查看錶的記錄數
查看student表的記錄數
count 'student'
五、刪除記錄
刪除student中rowkey001爲aget:colum1的值
delete 'student','rowkey001','age:colum1'
刪除整行的數據
deleteall 'student','rowkey001'
刪除整個表的數據
truncate 'student'