在學習Hbase的shell命令,之前先得瞭解如何進入hbase的shell命令行,通過執行如下簡單的命令回車後進入hbase的shell命令行界面 hbase shell 進入hbase命令行後,執行help然後回車,就能看到Hbase的shell命令行下有哪些命令,下麵是根據help反饋的幾類命 ...
在學習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'