启动hbase:

1.启动hadoop,因为hbase架设在hdfs之上,start-all.sh

2.启动hbase,start-hbase.sh,hbase网址端口16010

3.进入shell命令行,hbase shell

 

 

创建表:

create命令,需要指定表名和列族ColumnFamily

hbase(main):002:0> create 'table1','age'

0 row(s) in 1.4230 seconds

=> Hbase::Table - table1

hbase(main):003:0>

 

 

查看表:

list命令,查看有什么表

hbase(main):003:0> list

TABLE

table1

1 row(s) in 0.0150 seconds

=> ["table1"]

hbase(main):004:0>

 

 

查看table1表的具体信息:

decribe命令

hbase(main):007:0> describe 'table1'

Table table1 is ENABLED

table1

COLUMN FAMILIES DESCRIPTION

{NAME => 'age', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COM PRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '655 36', REPLICATION_SCOPE => '0'}

1 row(s) in 0.5440 seconds

hbase(main):008:0>

 

 

添加数据:

put命令

hbase(main):013:0> put 'table1','row1','age:male','mayu'

0 row(s) in 0.4380 seconds

hbase(main):014:0> put 'table1','row2','age:femal','mengqi'

0 row(s) in 0.0490 seconds

hbase(main):015:0> put 'table1','row3','age:xxx','xxx'

0 row(s) in 0.0040 seconds

hbase(main):016:0>

 

 

查看表中数据:

scan命令,扫描整个表

hbase(main):016:0> scan 'table1'

ROW COLUMN+CELL

row1 column=age:male, timestamp=1555814318188, value=mayu

row2 column=age:femal, timestamp=1555814362835, value=mengqi

row3 column=age:xxx, timestamp=1555814378959, value=xxx 3

row(s) in 0.0460 seconds

hbase(main):017:0>

get命令,取第一行

hbase(main):017:0> get 'table1','row1'

COLUMN CELL

age:male timestamp=1555814318188, value=mayu

1 row(s) in 0.0710 seconds

hbase(main):018:0>

 

 

禁用表:

disable禁用,enable启用

hbase(main):018:0> disable 'table1'

0 row(s) in 2.3650 seconds

hbase(main):020:0> enable 'table1'

0 row(s) in 1.3440 seconds

hbase(main):021:0>

 

 

删除表:

drop命令,删除表前要先禁用表,disable

hbase(main):003:0> disable 'table1'

0 row(s) in 2.3820 seconds

hbase(main):004:0> drop 'table1'

0 row(s) in 1.2940 seconds

hbase(main):005:0>

 

 

退出hbase shell:

quit命令或ctrl+c

hbase——2.hbase shell

 

 

启动hbase shell遇到错误:

单机版hbase启动失败,zookeeper.RecoverableZooKeeper: ZooKeeper exists failed after...

ookeeper.ZKUtil: hconnection-0x3078cac0x0, quorum=localhost:2181, baseZNode=/hbase Unable to set watcher on znode (/hbase/hbaseid)

org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss for /hbase/hbaseid

思路:

zookeeper异常,发现我是hadoop启动问题,没有namenode,重启hadoop解决,

也可能是没有启动hbase,启动hbase:start-hbase.sh

解决:

hadoop namenode -format(格式化namenode,记得要清空目录,core-site.xml里配置的hadoop.tmp.dir)

start-all.sh

start-hbase.sh

hbase shell

相关文章: