1. 基本 增 刪 改 查
[root@Node1 bin]# ./hbase shell ---# 啟動
hbase(main):001:0> create 'student','info' ---# 必須要有 '表名', '列簇‘
hbase(main):002:0> create 'hbase_test',{NAME => 'f1',VERSION => 1}
hbase(main):002:0> list ---# 相當於show tables
TABLE
student
test
2 row(s) in 0.1410 seconds
hbase(main):004:0> desc 'student' ---# 檢視錶結構
Table student is ENABLED
student
COLUMN FAMILIES DESCRIPTION
{NAME => 'info', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW',
REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'NONE',
MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'FALSE',
BLOCKSIZE => '65536', IN_MEMORY => 'false',BLOCKCACHE => 'true'}
1 row(s) in 0.8520 seconds
---# 插入資料
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','1001','info:name','Spark'
hbase(main):006:0> put 'student','1002','info:name','Janna'
hbase(main):007:0> put 'student','1002','info:sex','female'
hbase(main):008:0> put 'student','1002','info:age','20'
hbase(main):005:0> scan 'student' ---# 查詢資料
ROW COLUMN+CELL
1001 column=info:age, timestamp=1602493283192, value=18
1001 column=info:name, timestamp=1602493313879, value=Spark
1001 column=info:sex, timestamp=1602493233141, value=male
1002 column=info:age, timestamp=1602493327478, value=20
1002 column=info:name, timestamp=1602493292174, value=Janna
1002 column=info:sex, timestamp=1602493322683, value=female
2 row(s) in 1.2800 seconds
hbase(main):008:0> scan 'student',{STARTROW => '1001', STOPROW => '1001'}
ROW COLUMN+CELL
1001 column=info:age, timestamp=1602493283192, value=18
1001 column=info:name, timestamp=1602493313879, value=Spark
1001 column=info:sex, timestamp=1602493233141, value=male
1 row(s) in 0.1890 seconds
hbase(main):008:0> disable 'test' ---# 關閉表
hbase(main):008:0> drop 'test' ---# 刪除表
hbase(main):008:0> enable 'test' ---# 啟用表
hbase(main):008:0> truncate 'test' ---# 清空表中資料
hbase(main):010:0> get 'student','1001' ---# get 獲取資料
COLUMN CELL
info:age timestamp=1602493283192, value=18
info:name timestamp=1602493313879, value=Spark
info:sex timestamp=1602493233141, value=male
3 row(s) in 0.2800 seconds
hbase(main):011:0> get 'student','1001','info:name'
COLUMN CELL
info:name timestamp=1602493313879, value=Spark
1 row(s) in 0.1770 seconds
hbase(main):012:0> deleteall 'student','1001' ---# 刪除行
hbase(main):013:0> delete 'student','1002','f1:name' ---# 刪除列中欄位
hbase(main):014:0> put 'student','1002','info:age','24' ---# 更新指定欄位的資料
hbase(main):006:0> get 'student','1001','info:age'
COLUMN CELL
info:age timestamp=1602496498996, value=24
1 row(s) in 0.1150 seconds
hbase(main):008:0> alter 'student',{NAME=>'info',VERSIONS=>3} ---# 將info列族中的資料存放3個版本
Updating all regions with the new schema...
0/1 regions updated.
1/1 regions updated.
Done.
0 row(s) in 4.8640 seconds
hbase(main):018:0> put 'student','1001','info:age','27'
0 row(s) in 0.0370 seconds
hbase(main):019:0> get 'student','1001',{COLUMN=>'info:age',VERSIONS=>3}
COLUMN CELL
info:age timestamp=1602496931040, value=27
info:age timestamp=1602496498996, value=24
2 row(s) in 0.0710 seconds