官方文档
命名空间管理
创建 create_namespace 'foo'
查看list_namespace
删除 drop_namespace 'foo'
hbase(main):038:0> create_namespace 'foo'
Took 0.2400 seconds
hbase(main):039:0> list_namespace
NAMESPACE
DBATEST
FOO
ITEM
METADATA
SYSTEM
default
foo
hbase
item
tag
tag_user
trade
12 row(s)
Took 0.0128 seconds
hbase(main):040:0> drop_namespace 'foo'
Took 0.2300 seconds
表结构(增删改查)
default空间
新增表
create 'student','info'
hbase(main):005:0> create 'student','info'
Created table student
Took 0.7831 seconds
查看表
describe 'student'
hbase(main):008:0> describe 'student'
Table student is ENABLED
student
COLUMN FAMILIES DESCRIPTION
{NAME => 'info', 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', BLOOMFILTER => '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.1130 seconds
删除表
disable 'student'
drop 'student'
hbase(main):009:0> drop 'student'
ERROR: Table student is enabled. Disable it first.
Drop the named table. Table must first be disabled:
hbase> drop 't1'
hbase> drop 'ns1:t1'
Took 0.0242 seconds
hbase(main):010:0> disable 'student'
Took 0.7439 seconds
hbase(main):011:0> drop 'student'
Took 0.2303 seconds
插入数据
put 'student','1001','info:sex','male'
put 'student','1001','info:age','18'
put 'student','1002','info:name','Janna'
put 'student','1002','info:sex','female'
put 'student','1002','info:age','20'
hbase(main):016:0> put 'student','1001','info:age','18'
Took 0.0047 seconds
hbase(main):017:0> put 'student','1002','info:name','Janna'
Took 0.0042 seconds
hbase(main):018:0> put 'student','1002','info:sex','female'
Took 0.0044 seconds
hbase(main):019:0> put 'student','1002','info:age','20'
Took 0.0040 seconds
hbase(main):020:0> scan 'student'
ROW COLUMN+CELL
1001 column=info:age, timestamp=1651204670527, value=18
1001 column=info:sex, timestamp=1651204663172, value=male
1002 column=info:age, timestamp=1651204686340, value=20
1002 column=info:name, timestamp=1651204676388, value=Janna
1002 column=info:sex, timestamp=1651204681409, value=female
2 row(s)
Took 0.0674 seconds
更新数据
put 'student','1001','info:name','Nick'
put 'student','1001','info:age','100'
hbase(main):021:0> put 'student','1001','info:name','Nick'
Took 0.0046 seconds
hbase(main):022:0> put 'student','1001','info:age','100'
Took 0.0043 seconds
hbase(main):023:0> scan 'student'
ROW COLUMN+CELL
1001 column=info:age, timestamp=1651204878584, value=100
1001 column=info:name, timestamp=1651204872386, value=Nick
1001 column=info:sex, timestamp=1651204663172, value=male
1002 column=info:age, timestamp=1651204686340, value=20
1002 column=info:name, timestamp=1651204676388, value=Janna
1002 column=info:sex, timestamp=1651204681409, value=female
2 row(s)
Took 0.0127 seconds
删除数据
删除某 rowkey 的全部数据
deleteall 'student','1001'
hbase(main):024:0> deleteall 'student','1001'
Took 0.0145 seconds
hbase(main):025:0> scan 'student'
ROW COLUMN+CELL
1002 column=info:age, timestamp=1651204686340, value=20
1002 column=info:name, timestamp=1651204676388, value=Janna
1002 column=info:sex, timestamp=1651204681409, value=female
1 row(s)
Took 0.0101 seconds
删除某 rowkey 的某一列数据
delete 'student','1002','info:sex'
hbase(main):002:0> delete 'student','1002','info:sex'
Took 0.5544 seconds
hbase(main):003:0> scan 'student'
ROW COLUMN+CELL
1002 column=info:age, timestamp=1651204686340, value=20
1002 column=info:name, timestamp=1651204676388, value=Janna
1 row(s)
Took 0.0331 seconds
清空表数据
truncate 'student'
hbase(main):004:0> truncate 'student'
Truncating 'student' table (it may take a while):
Disabling table...
Truncating table...
Took 1.6289 seconds
同理,创建指定命名空间的表,创建foo命名空间,表student
创建表
create 'foo:student','info'
查看表结构
describe 'foo:student'
删除表
disable 'foo:student'
drop 'foo:student'
插入数据
put 'foo:student','1001','info:sex','male'
put 'foo:student','1001','info:age','18'
put 'foo:student','1002','info:name','Janna'
put 'foo:student','1002','info:sex','female'
put 'foo:student','1002','info:age','20'
更新
put 'foo:student','1001','info:name','Nick'
put 'foo:student','1001','info:age','100'
查看表数据
scan 'foo:student'
删除 rowkey为1001的数据
deleteall 'foo:student','1001'
删除rowkey为1002,列为sex的数据
delete 'foo:student','1002','info:sex'
删除表数据
truncate 'foo:student'