Hbase简单使用-shell命令

如何进入Hbase数据库

    

[root@node127 bin]# hbase shell
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/console/hbase/lib/slf4j-log4j12.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/console/hadoop/hadoop/lib/slf4j-log4j12.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/console/hbase/lib/client-facing-thirdparty/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
HBase Shell
Use "help" to get list of supported commands.
Use "exit" to quit this interactive shell.
For Reference, please visit: http://hbase.apache.org/2.0/book.html#shell
Version 2.1.0-cdh6.1.1, rUnknown, Thu Feb  7 22:49:02 PST 2019
Took 0.0036 seconds   

一般操作

  查询服务器状态

hbase(main):001:0> status
1 active master, 1 backup masters, 3 servers, 0 dead, 1.0000 average load
Took 1.3630 seconds  

  查询当前用户

hbase(main):003:0> whoami
root (auth:SIMPLE)
    groups: root
Took 0.0835 seconds  

  查询当前版本

hbase(main):004:0> version
2.1.0-cdh6.1.1, rUnknown, Thu Feb  7 22:49:02 PST 2019
Took 0.0012 seconds  

  

ddl操作

  列出所有命名空间

hbase(main):006:0> list_namespace
NAMESPACE                                                                               
default                                                                                 
hbase                                                                                   
2 row(s)
Took 1.8528 seconds 

  新建命名空间

hbase(main):007:0> create_namespace 'li_hbase'
Took 0.4772 seconds   

  新建表:li_hbase空间下,表t1,列族cf1

hbase(main):010:0> create 'li_hbase:t1', 'cf1'
Created table li_hbase:t1
Took 4.8559 seconds                                                                     
=> Hbase::Table - li_hbase:t1
hbase(main):011:0> list
TABLE                                                                                   
li_hbase:t1                                                                             
1 row(s)
Took 0.0327 seconds                                                                     
=> ["li_hbase:t1"]

  创建表t2插入数据

hbase(main):022:0> create 'li_hbase:t2', 'cf1'
Created table li_hbase:t2
Took 1.4216 seconds                                                                     
=> Hbase::Table - li_hbase:t2
hbase(main):023:0> put 'li_hbase:t2','1','cf1:name','孙悟空'
Took 0.1548 seconds                                                                     
hbase(main):024:0> put 'li_hbase:t2','1','cf1:sex','男'
Took 0.0150 seconds                                                                     
hbase(main):025:0> put 'li_hbase:t2','1','cf1:age','19'
Took 0.0117 seconds                                                                     
hbase(main):026:0> put 'li_hbase:t2','2','cf1:name','angela'
Took 0.0104 seconds                                                                     
hbase(main):027:0> put 'li_hbase:t1','2','cf1:sex','女'
Took 0.0163 seconds                                                                     
hbase(main):028:0> put 'li_hbase:t2','2','cf1:age','19'
Took 0.0137 seconds                                                                     
hbase(main):029:0> put 'li_hbase:t2','2','cf1:sex','女'
Took 0.0076 seconds  

  查询数据

汉字为16进制

hbase(main):030:0> scan 'li_hbase:t2'
ROW                     COLUMN+CELL                                                     
 1                      column=cf1:age, timestamp=1574219211337, value=19               
 1                      column=cf1:name, timestamp=1574219186848, value=\xE5\xAD\x99\xE6
                        \x82\x9F\xE7\xA9\xBA                                            
 1                      column=cf1:sex, timestamp=1574219200445, value=\xE7\x94\xB7     
 2                      column=cf1:age, timestamp=1574219269247, value=19               
 2                      column=cf1:name, timestamp=1574219249911, value=angela          
 2                      column=cf1:sex, timestamp=1574219276096, value=\xE5\xA5\xB3     
2 row(s)
Took 0.0208 seconds  

  

  create:创建数据库表,创建命令可看帮助help 'create'

  语法:create <table>, {NAME =><family>, VERSIONS => <VERSIONS>}

  例示:create 'product',{NAME => 'computer', VERSIONS => 5},{ NAME => 'food' , VERSIONS => 3}

  描述:创建一张名叫'product'数据库表,并且创建两个列族,分别为:'computer'、'food'

猜你喜欢

转载自www.cnblogs.com/l7planet/p/11895928.html