Hbase shell 操作记录
查看hbase版本
hbase(main):002:0> version
2.1.0-cdh6.2.0, rUnknown, Wed Mar 13 23:39:58 PDT 2019
Took 0.0003 seconds
Hbase表空间概念
1、介绍
在HBase中,namespace命名空间指对一组表的逻辑分组,类似RDBMS中的database,方便对表在业务上划分。Apache HBase从0.98.0, 0.95.2两个版本开始支持namespace级别的授权操作,HBase全局管理员可以创建、修改和回收namespace的授权。
2、namespace
HBase系统默认定义了两个缺省的namespace
hbase:系统内建表,包括namespace和meta表
default:用户建表时未指定namespace的表都创建在此
hbase 查看命名空间
hbase(main):001:0> list_namespace
NAMESPACE
default
hbase
2 row(s)
Took 0.5695 seconds
创建表空间
hbase(main):005:0> create_namespace 'grady'
Took 0.5849 seconds
hbase(main):006:0> list_namespace
NAMESPACE
default
grady
hbase
3 row(s)
Took 0.0123 seconds
在表空间下创建表
create 'table_name', 'family1', 'family2', 'familyN'
表至少要包含一个列簇
hbase(main):008:0> create 'grady:student'
ERROR: Table must have at least one column family
For usage try 'help "create"'
Took 0.0117 seconds
正确例子
hbase(main):010:0> create 'grady:student', 'colfam01'
Created table grady:student
Took 2.5297 seconds
=> Hbase::Table - grady:student
查看命名空间下的表
hbase(main):011:0> list_namespace_tables 'grady'
TABLE
student
1 row(s)
Took 0.0289 seconds
=> ["student"]
列出所有表
hbase(main):012:0> list
TABLE
grady:student
1 row(s)
Took 0.0291 seconds
=> ["grady:student"]
删除命名空间
drop_namespace 'grady'
禁用表
disable 'grady:student'
启用表
enable ‘grady:student’
表是否启动或者禁用
is_enabled 'table1'
is_disabled 'table1'
删除表(先禁用再删除)
disable 'grady:student'
drop 'grady:student'
获取表描述信息
hbase(main):015:0> describe 'grady:student'
Table grady:student is ENABLED
grady:student
COLUMN FAMILIES DESCRIPTION
{NAME => 'colfam01', VERSIONS => '1', EVICT_BLOCKS_ON_CLOSE => 'false', NEW_VERSION_BEHAVIOR => 'false', KEEP_DELETED_CELLS => 'FALSE
', CACHE_DATA_ON_WRITE => 'false', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', REPLICATION_SCOPE => '0', BL
OOMFILTER => 'ROW', CACHE_INDEX_ON_WRITE => 'false', IN_MEMORY => 'false', CACHE_BLOOMS_ON_WRITE => 'false', PREFETCH_BLOCKS_ON_OPEN
=> 'false', COMPRESSION => 'NONE', BLOCKCACHE => 'true', BLOCKSIZE => '65536'}
1 row(s)
Took 0.2017 seconds
dml 数据操作
插入数据
put 'grady:student' , 'jiang' , 'colfam01:age' , '24'
put 'grady:student' , 'jiang' , 'colfam01:city' , 'wuhan'
全表数据扫描
hbase(main):020:0> scan 'grady:student'
ROW COLUMN+CELL
jiang column=colfam01:age, timestamp=1643384572444, value=24
jiang column=colfam01:city, timestamp=1643384598828, value=wuhan
1 row(s)
Took 0.0072 seconds
获得一行所有的数据(根据rowkey)
hbase(main):023:0> get 'grady:student', 'jiang'
COLUMN CELL
colfam01:age timestamp=1643384572444, value=24
colfam01:city timestamp=1643384598828, value=wuhan
1 row(s)
Took 0.0684 seconds
获取某一行某一列簇的数据
hbase(main):025:0> get 'grady:student', 'jiang', 'colfam01'
COLUMN CELL
colfam01:age timestamp=1643384572444, value=24
colfam01:city timestamp=1643384598828, value=wuhan
1 row(s)
Took 0.0064 seconds
获取某一行某一列的数据
hbase(main):024:0> get 'grady:student', 'jiang', 'colfam01:city'
COLUMN CELL
colfam01:city timestamp=1643384598828, value=wuhan
1 row(s)
Took 0.0197 seconds
更新某一行某一列的数据
hbase(main):026:0> put 'grady:student' , 'jiang' , 'colfam01:city' , 'wuhan-hongshan'
Took 0.0102 seconds
hbase(main):027:0> scan 'grady:student'
ROW COLUMN+CELL
jiang column=colfam01:age, timestamp=1643384572444, value=24
jiang column=colfam01:city, timestamp=1643385119877, value=wuhan-hongshan
1 row(s)
Took 0.0073 seconds
查询表中数据量
hbase(main):028:0> count 'grady:student'
1 row(s)
Took 0.0434 seconds
=> 1
清空表
truncate 'member'
删除某行的某一列的数据
先插入chen的数据
hbase(main):029:0> put 'grady:student' , 'chen' , 'colfam01:city' , 'wuhan-hongshan'
Took 0.0097 seconds
hbase(main):030:0> put 'grady:student' , 'chen' , 'colfam01:age' , '25'
Took 0.0116 seconds
hbase(main):031:0> scan 'grady:student'
ROW COLUMN+CELL
chen column=colfam01:age, timestamp=1643385532711, value=25
chen column=colfam01:city, timestamp=1643385510256, value=wuhan-hongshan
jiang column=colfam01:age, timestamp=1643384572444, value=24
jiang column=colfam01:city, timestamp=1643385119877, value=wuhan-hongshan
hbase(main):032:0> delete 'grady:student', 'chen', 'colfam01:age'
Took 0.0094 seconds
删除整行数据
hbase(main):006:0> deleteall 'grady:student', 'chen'
Took 0.0642 seconds
表结构修改
新增列簇
alter 'grady:student', 'cf2'
删除列簇
alter 'grady:student', 'delete' => 'cf2'
Hbase 使用LIMIT查询前10条数据
scan 'test-table', {'LIMIT' => 10}
参考:
https://blog.csdn.net/kangkangwanwan/article/details/60960731