Hbase 查询语句

2020-05-01  本文已影响0人  HAO延WEI

进入HBase数据库

hbase shell

HBase帮助命令:

hbase> help 'create'

命名空间

列出所有命名空间
hbase> list_namespace
新建命名空间
hbase> create_namespace 'ns1'
删除命名空间
hbase> drop_namespace 'ns1'

该命名空间必须为空,否则系统不让删除

修改命名空间
hbase> alter_namespace 'ns', {METHOD => 'set', 'PROPERTY_NAME' => 'PROPERTY_VALUE'}

列出所有表
hbase> list
列出指定命名空间下的所有表
hbase> list_namespace_tables 'ns1'
新建表
hbase> create 'ns1:t1', 'cf1'

新建一个以命名空间ns1的表t1,列族为cf1。

删除表
hbase> disable 'ns1:t1'
hbase> drop 'ns1:t1'
查看表内容
hbase> scan 'ns1:t1'
hbase> scan 'ns1:t1', {LIMIT=>5} # 查看前5行数据
插入
hbase> put 'ns1:t1', 'r1', 'cf1:c1', 'value'

比如我们插入以下数据:

id name sex age
1 孙悟空 18
2 安琪拉 19
3 狄仁杰 20
put 'gld:student','1','cf1:name','孙悟空'
put 'gld:student','1','cf1:sex','男'
put 'gld:student','1','cf1:age','18'

put 'gld:student','2','cf1:name','安琪拉'
put 'gld:student','2','cf1:sex','女'
put 'gld:student','2','cf1:age','19'

put 'gld:student','3','cf1:name','狄仁杰'
put 'gld:student','3','cf1:sex','男'
put 'gld:student','3','cf1:age','20'

hbase> scan 'gld:student'
ROW                                                          COLUMN+CELL                                                                                                                                                                       
 1                                                           column=cf1:age, timestamp=1538030949261, value=18                                                                                                                                 
 1                                                           column=cf1:name, timestamp=1538030949174, value=\xE5\xAD\x99\xE6\x82\x9F\xE7\xA9\xBA                                                                                              
 1                                                           column=cf1:sex, timestamp=1538030949219, value=\xE7\x94\xB7                                                                                                                       
 2                                                           column=cf1:age, timestamp=1538030949393, value=19                                                                                                                                 
 2                                                           column=cf1:name, timestamp=1538030949314, value=\xE5\xAE\x89\xE7\x90\xAA\xE6\x8B\x89                                                                                              
 2                                                           column=cf1:sex, timestamp=1538030949350, value=\xE5\xA5\xB3                                                                                                                       
 3                                                           column=cf1:age, timestamp=1538030950752, value=20                                                                                                                                 
 3                                                           column=cf1:name, timestamp=1538030949448, value=\xE7\x8B\x84\xE4\xBB\x81\xE6\x9D\xB0                                                                                              
 3                                                           column=cf1:sex, timestamp=1538030949487, value=\xE7\x94\xB7                                                                                                                       
3 row(s) in 0.0230 seconds

查看

hbase> get 'ns1:t1', 'r1'

快照

hbase> list_snapshots 'ns1'
上一篇 下一篇

猜你喜欢

热点阅读