1. Hbase版本查看
hbase(main):008:0> version 2.2.3, r6a830d87542b766bd3dc4cfdee28655f62de3974, 2020年 01月 10日 星期五 18:27:51 CST Took 0.0002 seconds
2. Hbase状态查看命令shell
hbase(main):009:0> status 1 active master, 0 backup masters, 1 servers, 0 dead, 3.0000 average load Took 0.0387 seconds
1. 新建表test 设置两个列族为cf1,cf2
hbase(main):010:0> create 'test','cf1','cf2' Created table test Took 1.3418 seconds => Hbase::Table - test
2. 获取表的描述
hbase(main):011:0> describe 'test' Table test is ENABLED test COLUMN FAMILIES DESCRIPTION {NAME => 'cf1', VERSIONS => '1', EVICT_BLOCKS_ON_CLOSE => 'false', NEW_VERSION_B EHAVIOR => 'false', KEEP_DELETED_CELLS => 'FALSE', CACHE_DATA_ON_WRITE => 'false ', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', REPLICA TION_SCOPE => '0', BLOOMFILTER => 'ROW', CACHE_INDEX_ON_WRITE => 'false', IN_MEM ORY => 'false', CACHE_BLOOMS_ON_WRITE => 'false', PREFETCH_BLOCKS_ON_OPEN => 'fa lse', COMPRESSION => 'NONE', BLOCKCACHE => 'true', BLOCKSIZE => '65536'} {NAME => 'cf2', VERSIONS => '1', EVICT_BLOCKS_ON_CLOSE => 'false', NEW_VERSION_B EHAVIOR => 'false', KEEP_DELETED_CELLS => 'FALSE', CACHE_DATA_ON_WRITE => 'false ', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', REPLICA TION_SCOPE => '0', BLOOMFILTER => 'ROW', CACHE_INDEX_ON_WRITE => 'false', IN_MEM ORY => 'false', CACHE_BLOOMS_ON_WRITE => 'false', PREFETCH_BLOCKS_ON_OPEN => 'fa lse', COMPRESSION => 'NONE', BLOCKCACHE => 'true', BLOCKSIZE => '65536'} 2 row(s) QUOTAS 0 row(s) Took 16.3063 seconds
3. 删除一个列族cf2
hbase(main):012:0> alter 'test', {NAME=>'cf2',METHOD=>'delete'} Updating all regions with the new schema... 1/1 regions updated. Done. Took 2.0665 seconds
4. 列出所有Hbase里的表
hbase(main):013:0> list TABLE table test 2 row(s) Took 0.0044 seconds => ["table", "test"]
5. 查询表是否存在
hbase(main):014:0> exists 'test' Table test does exist Took 0.0224 seconds => true
6. 查询表是否可用
hbase(main):015:0> is_enabled 'test' true Took 0.0053 seconds => true
7. 删除一个表
hbase(main):017:0> disable 'test' Took 0.4657 seconds hbase(main):018:0> drop 'test' Took 0.2485 seconds
1. 插入数据
给Hbase的test表的row1行 插入两个列。
hbase(main):034:0> put 'test','row1','cf1:name','tom' Took 0.0080 seconds hbase(main):035:0> put 'test','row1','cf1:age','18' Took 0.0043 seconds
列族cf1 定义了两个列 name 和 age
2. 读取数据
读取test 表的row1行的所有数据
hbase(main):036:0> get 'test','row1' COLUMN CELL cf1:age timestamp=1581128757386, value=18 cf1:name timestamp=1581128743387, value=tom 1 row(s) Took 0.0264 seconds
读取test row1行,列族cf1所有数据
hbase(main):037:0> get 'test','row1','cf1' COLUMN CELL cf1:age timestamp=1581128757386, value=18 cf1:name timestamp=1581128743387, value=tom 1 row(s) Took 0.0083 seconds
3. 更新一条记录
Hbase的更新语法和插入新数据语法一样
hbase(main):038:0> put 'test','row1','cf1:age','19' Took 0.0059 seconds
查看更新结果
hbase(main):039:0> get 'test','row1','cf1:age' COLUMN CELL cf1:age timestamp=1581130589721, value=19 1 row(s) Took 0.0133 seconds
4. 通过时间戳读取两个版本的数据
hbase(main):005:0> get 'test','row1',{COLUMN=>'cf1:age',TIMESTAMP=>1581130589721} COLUMN CELL cf1:age timestamp=1581130589721, value=19 1 row(s) Took 0.0082 seconds hbase(main):008:0> get 'test','row1',{COLUMN=>'cf1:age',TIMESTAMP=>1581128757386} COLUMN CELL cf1:age timestamp=1581128757386, value=18 1 row(s) Took 0.0135 seconds
5. 全表扫描
hbase(main):009:0> scan 'test' ROW COLUMN+CELL row1 column=cf1:age, timestamp=1581130589721, value=19 row1 column=cf1:name, timestamp=1581128743387, value=tom 1 row(s) Took 0.0107 seconds
6.统计表中行数
hbase(main):017:0> count 'test' 1 row(s) Took 0.0635 seconds => 1
7. 删除一列
hbase(main):011:0> delete 'test','row1','cf1:age' Took 0.0269 seconds
检查删除的结果,年龄回到了18,把19那条删除了
hbase(main):012:0> get 'test','row1' COLUMN CELL cf1:age timestamp=1581128757386, value=18 cf1:name timestamp=1581128743387, value=tom 1 row(s) Took 0.0114 seconds
再次删除
hbase(main):015:0> delete 'test','row1','cf1:age' Took 0.0030 seconds hbase(main):014:0> get 'test','row1' COLUMN CELL cf1:name timestamp=1581128743387, value=tom 1 row(s) Took 0.0134 seconds
8. 删除所有的单元格
hbase(main):020:0> deleteall 'test','row1' Took 0.0041 seconds
9. 清空表所有数据
hbase(main):022:0> truncate 'test' Truncating 'test' table (it may take a while): Disabling table... Truncating table... Took 1.5547 seconds
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!