1. 程式人生 > >Hbase資料庫的常用操作命令

Hbase資料庫的常用操作命令

HBase的DDL操作
1、建立namespace
-》檢視幫助資訊,找到建立的語法格式:help 'create_namespace',注意要加上引號
create_namespace 'nstest'
2、描述檢視namespace的結構
describe_namespace 'nstest'
3、刪除namespace
drop_namespace 'nstest2'


4、建立表
示例: create 'ns1:t1', {NAME => 'f1', VERSIONS => 5}
-》ns1指的就是namespace
-》t1代表table_name
-》ns1:t1這樣的格式就是唯一確定了一張表
-》在hbase中=>符號表示等於
-》f指的是列簇
-》VERSIONS => 5代表同時能夠儲存的版本數
-》建表時要指定一個列簇
-》可以指定多個列簇,一個大括號中只能指定一個NAME(變數)
-》一個列簇就是一個大括號
建表:
create 'stu_test','f1'
create 't1', 'f1', 'f2', 'f3'
create 'nstest:tb1','info'
在建表的時候可以指定在某個namespace下,比如:ns1:t1,沒有指定就是在預設的資料庫下面建立


/hbase/data 該目錄下存放 namespace namespace下有相對應的表


描述表結構
desc 't1'


刪除表:


在hbase中表有啟用和禁用的狀態區分,在刪除和修改前需要先禁用,如果是修改那麼完成後需要再啟用


禁用:
disable 't1'


刪除:
drop 't1'


禁用
disable, disable_all
啟用
enable, enable_all


六、HBase的DML操作
1、新增資料
示例:put 'ns1:t1', 'r1', 'c1', 'value'
-》r代表rowkey
-》c代表列+列簇
-》value代表具體插入的值


插入值:必須唯一確定到一個值
put 'nstest:tb1','20170521_10001','info:name','leo'
put 'nstest:tb1','20170521_10001','info:age','18'
put 'nstest:tb1','20170521_10001','info:sex','male'
put 'nstest:tb1','20170521_10002','info:name','jack'
put 'nstest:tb1','20170521_10003','info:name','tom'


2、查詢資料
示例:get 'ns1:t1', 'r1'


get 'nstest:tb1','20170521_10001'


一個rowkey可能有多個列簇,可以指定列簇進行查詢
get 'nstest:tb1','20170521_10001','info'
指定某一列查詢
get 'nstest:tb1','20170521_10001','info:name'


scan:表示全表掃描  -》類似select * 
scan 'table_name'
scan 'nstest:tb1'


STARTROW代表開始的行號


scan 'ns1:t1', {COLUMNS => ['c1', 'c2'], LIMIT => 10, STARTROW => 'xyz'}


scan 'nstest:tb1', {STARTROW => '20170521_10002'}


-》大括號中的所有變數都必須是大寫


scan 'nstest:tb1', {STARTROW => '20170521_10001',STOPROW => '20170521_10003'}


STARTROW:包含頭部的列簇到結尾
STOPROW:包頭不包尾


3、刪除 
deleteall直接刪除列簇
deleteall 'test:toltable','20170521_10003'
delete 'nstest:tb1','20170521_10001','info:name'


put 'nstest:tb1','20170521_10001','info:age','20'-------修改