尚硅谷大數(shù)據(jù)技術(shù)之HBase第4章 HBase Shell操作

4.1 基本操作

1)?進(jìn)入HBase客戶端命令行

[atguigu@hadoop102?hbase]$ bin/hbase shell

2)查看幫助命令

hbase(main):001:0> help

3)查看當(dāng)前數(shù)據(jù)庫(kù)中有哪些表

hbase(main):002:0> list

4.2 表的操作

1)創(chuàng)建表

hbase(main):002:0> create 'student','info'

2)插入數(shù)據(jù)到表
hbase(main):003:0> put 'student','1001','info:sex','male'

hbase(main):004:0> put 'student','1001','info:age','18'

hbase(main):005:0> put 'student','1002','info:name','Janna'

hbase(main):006:0> put 'student','1002','info:sex','female'

hbase(main):007:0> put 'student','1002','info:age','20'

3)掃描查看表數(shù)據(jù)

hbase(main):008:0> scan 'student'

hbase(main):009:0> scan 'student',{STARTROW => '1001', STOPROW ?=> '1001'}

hbase(main):010:0> scan 'student',{STARTROW => '1001'}

4)查看表結(jié)構(gòu)

hbase(main):011:0> describe ‘student’

5)更新指定字段的數(shù)據(jù)

hbase(main):012:0> put 'student','1001','info:name','Nick'

hbase(main):013:0> put 'student','1001','info:age','100'

6)查看“指定行”或“指定列族:列”的數(shù)據(jù)

hbase(main):014:0> get 'student','1001'

hbase(main):015:0> get 'student','1001','info:name'

7)統(tǒng)計(jì)表數(shù)據(jù)行數(shù)

hbase(main):021:0> count 'student'

8)刪除數(shù)據(jù)

刪除某rowkey的全部數(shù)據(jù):

hbase(main):016:0> deleteall 'student','1001'

刪除某rowkey的某一列數(shù)據(jù):

hbase(main):017:0> delete 'student','1002','info:sex'

9)清空表數(shù)據(jù)

hbase(main):018:0> truncate 'student'

提示:清空表的操作順序?yàn)橄萪isable,然后再truncate。

10)刪除表

首先需要先讓該表為disable狀態(tài):

hbase(main):019:0> disable 'student'

然后才能drop這個(gè)表:

hbase(main):020:0> drop 'student'

提示:如果直接drop表,會(huì)報(bào)錯(cuò):Drop the named table. Table must first be disabled

ERROR: Table student is enabled. Disable it first.

11)變更表信息

將info列族中的數(shù)據(jù)存放3個(gè)版本:

hbase(main):022:0> alter 'student',{NAME=>'info',VERSIONS=>3}

 

本教程由尚硅谷教育大數(shù)據(jù)研究院出品,如需轉(zhuǎn)載請(qǐng)注明來(lái)源,歡迎大家關(guān)注尚硅谷公眾號(hào)(atguigu)了解更多。