Hbase的shell命令學(xué)習(xí)<一>

在學(xué)習(xí)Hbase的shell命令,之前先得了解如何進(jìn)入hbase的shell命令行,通過執(zhí)行如下簡(jiǎn)單的命令回車后進(jìn)入hbase的shell命令行界面

hbase shell

進(jìn)入hbase命令行后,執(zhí)行help然后回車,就能看到Hbase的shell命令行下有哪些命令,下面是根據(jù)help反饋的幾類命令來進(jìn)行學(xué)習(xí):

一、 general commands

Command list: status, table_help, version, whoami

1、查看整理的狀態(tài)

hbase(main):007:0> status

1 servers, 0 dead, 4.0000 average load

2、查看表涉及的命令對(duì)應(yīng)的幫助

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、查看當(dāng)前用戶

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、創(chuàng)建表(create)

2.1 創(chuàng)建student的表,含有name、address、age列族

create 'student','name','address','age'

2.2 創(chuàng)建namespace為hbase并且表名為t4的表

create 'hbase:t4',{NAME => 'f1'}

3、查看表(describe)

語法:?describe 'tablename' or describe 'namespace:tablename'

備注:也可以使用縮寫的desc來查看

3.1 查看創(chuàng)建的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、創(chuàng)建表空間

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的數(shù)據(jù)

scan 'student'

只掃描stdent的前2行記錄

scan 'student',{LIMIT => 2}

4、查看表的記錄數(shù)

查看student表的記錄數(shù)

count 'student'

5、刪除記錄

刪除student中rowkey001為aget:colum1的值

delete 'student','rowkey001','age:colum1'

刪除整行的數(shù)據(jù)

deleteall 'student','rowkey001'

刪除整個(gè)表的數(shù)據(jù)

truncate 'student'

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容