目录
1.基本操作
- 进入 HBase 客户端命令行
[atguigu@hadoop102 hbase]$ bin/hbase shell
- 查看帮助命令
hbase(main):001:0> help
- 查看当前数据库中有哪些表
hbase(main):002:0> list
2.表的操作 DDL
2.1 创建表和列族
hbase(main):009:0> create 'student','info','address' //student:表名 列族:info address
Created table student
Took 1.2751 seconds
=> Hbase::Table - student
2.2 查看表的描述:describe
hbase(main):011:0> describe 'student'
Table student is ENABLED
student
COLUMN FAMILIES DESCRIPTION
{NAME => 'address', 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 => 'FORE
VER', 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', COMPRESSIO
N => 'NONE', BLOCKCACHE => 'true', BLOCKSIZE => '65536'}
{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'}
2 row(s)
Took 0.1581 seconds
2.3 查看表的描述:desc
desc 'student'
Table student is ENABLED
student
COLUMN FAMILIES DESCRIPTION
{NAME => 'address', 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 => 'FORE
VER', 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', COMPRESSIO
N => 'NONE', BLOCKCACHE => 'true', BLOCKSIZE => '65536'}
{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'}
2 row(s)
Took 0.0500 seconds
2.4 判断某表是否存在:exists
hbase(main):013:0> exists 'student'
Table student does exist
Took 0.0185 seconds
=> true
2.5 判断某表是否被禁用:is_disabled
hbase(main):014:0> is_disabled 'student'
false //fales:没有被禁用
Took 0.0346 seconds
=> 1
2.6 判断某表是否在启用:is_enabled
hbase(main):015:0> is_enabled 'student'
true //true :正在启用状态
Took 0.0098 seconds
=> true
2.7 禁用表:disable
hbase(main):017:0> disable 'student'//禁用student表
Took 0.8065 seconds
hbase(main):018:0> is_disabled 'student'//查看是否被禁用
true //已被禁用
Took 0.0124 seconds
=> 1
2.8 启用表:enable
hbase(main):024:0> enable 'student'
Took 0.8293 seconds
2.9 删除表:drop
删除表这里要说一下,只有被禁用的表,才能被drop删除,所以说我们先禁用再删除
hbase(main):019:0> drop 'student'
Took 0.4638 seconds
2.10 删除列族:alter 表,delete=>列族
hbase(main):028:0> alter 'student','delete'=>'address'
Updating all regions with the new schema...
1/1 regions updated.
Done.
Took 2.0847 seconds
2.11 新增列族:alter 表, NAME=>列族
alter 'student,'NAME'=>'address'
2.12 删除多个表(首先要禁用多个表)
删除多个表: disable_all drop_all
首先全部禁用
disable_all 'stu.*'
drop_all 'stu.*' //删除以stu开头的所有表
3.数据的操作 DML
3.1 添加数据:put
hbase(main):004:0> put 'student','1001','info:name','zhangsna'
//1001:是rowkey
Took 0.5393 seconds
hbase(main):007:0> put 'student','1002','info:name','lisi'
Took 0.0104 seconds
3.2 查看数据:scan
scan 'student'
ROW COLUMN+CELL
1001 column=info:name, timestamp=1537408041183, value=zhangsna
1 row(s)
Took 0.0767 seconds
3.3 修改表中数据
我们可以发现,添加既是修改,是属于同一语句
put 'student','1002','info:name','wangwu'
Took 0.0134 seconds
hbase(main):010:0> scan 'student'
ROW COLUMN+CELL
1001 column=info:name, timestamp=1537408041183, value=zhangsna
1002 column=info:name, timestamp=1537408278285, value=wangwu
3.4 查询数据:get
get 'student','1002'
COLUMN CELL
info:name timestamp=1537408278285, value=wangwu
1 row(s)
Took 0.0212 seconds
3.5 查询扫描整个表
hbase(main):032:0> scan 'student'
ROW COLUMN+CELL
1001 column=address:phone, timestamp=1537408682430, value=10086
1001 column=info:name, timestamp=1537408041183, value=zhangsna
1002 column=info:name, timestamp=1537408278285, value=wangwu
2 row(s)
Took 0.0124 seconds
3.6 删除数据:delete
delete 'student','1001','address:phone'
3.7 删除整行数据
deleteall 'student','1002'
3.8 查看表中总记录数
hbase(main):046:0> count 'student'
1 row(s)
Took 0.2269 seconds
=> 1
3.9 清空表中数据
hbase(main):047:0> truncate 'student'
Truncating 'student' table (it may take a while):
Disabling table...
Truncating table...
Took 2.3399 seconds