【大数据学习 | HBASE】hbase shell基础实操

1. 查看hbase状态

java 复制代码
# 进入hbase 命令行
hbase shell
status

我这里没启用高可用hbase

java 复制代码
1 active master, 0 backup masters, 2 servers, 1 dead, 1.0000 average load
Took 5.2635 seconds  

2. 查看版本号

java 复制代码
version
java 复制代码
hbase:002:0> version
2.4.11, r7e672a0da0586e6b7449310815182695bc6ae193, Tue Mar 15 10:31:00 PDT 2022
Took 0.0006 seconds  

3. 命名空间操作

java 复制代码
# 创建命名空间
create_namespace '命名空间名'

# 显示所有命名空间
list_namespace

# 删除命名空间
drop_namespace '命名空间名'

# 查看命名空间中的表有什么
list_namespace_tables
java 复制代码
hbase:001:0> list_namespace
NAMESPACE                                                                                                      
default                                                                                                        
hbase                                                                                                          
2 row(s)
Took 0.8956 seconds                                                                                            
hbase:002:0> create_namespace 'hainiu'
Took 0.3163 seconds                                                                                            
hbase:003:0> list_namespace
NAMESPACE                                                                                                      
default                                                                                                        
hainiu                                                                                                         
hbase                                                                                                          
3 row(s)
Took 0.0371 seconds                                                                                            
hbase:004:0> drop_namespace 'hainiu'
Took 0.1986 seconds                                                                                            
hbase:005:0> list_namespace
NAMESPACE                                                                                                      
default                                                                                                        
hbase                                                                                                          
2 row(s)
Took 0.0247 seconds         

4. 创建表

java 复制代码
# 创建默认命名空间的表
create '表名称', '列族名称1','列族名称2','列族名称N'

# 创建带有命名空间的表
create '命名空间:表名称', '列族名称1','列族名称2','列族名称N'
java 复制代码
hbase:007:0> create 'hainiu:info','info1','info2', 'info3'
Created table hainiu:info
Took 2.4064 seconds                                                                                            
=> Hbase::Table - hainiu:info
-- 指定了命名空间,即在该指定的命名空间下创建表,否则就默认在default下创建表。
-- 创建表必须指明列族
-- hainiu是命名空间,info是表,info1,info2,info3是列族

创建完之后有一个region是上线的

状态和该表region的位置:

5. 列出所有的表

java 复制代码
# 查看所有的表
list

# 查询指定命名空间下的表
list_namespace_tables '命名空间'
java 复制代码
hbase:012:0> list
TABLE                                                                                                          
hainiu:info                                                                                                    
1 row(s)
Took 0.1127 seconds                                                                                            
=> ["hainiu:info"]
hbase:013:0> list_namespace_tables 'hainiu'
TABLE                                                                                                          
info                                                                                                           
1 row(s)
Took 0.0161 seconds                                                                                            
=> ["info"]

只显示用户创建的表信息

6. 获取表的描述

java 复制代码
# 默认命名空间
describe '表名'

# 指定命名空间
describe '命名空间:表名'
java 复制代码
hbase:001:0> describe 'hainiu:info'
Table hainiu:info is ENABLED                                                                                   
hainiu:info                                                                                                    
COLUMN FAMILIES DESCRIPTION                                                                                    
{NAME => 'info1', BLOOMFILTER => 'ROW', IN_MEMORY => 'false', VERSIONS => '1', KEEP_DELETED_CELLS => 'FALSE', D
ATA_BLOCK_ENCODING => 'NONE', COMPRESSION => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', BLOCKCACHE => 'true
', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}                                                             

{NAME => 'info2', BLOOMFILTER => 'ROW', IN_MEMORY => 'false', VERSIONS => '1', KEEP_DELETED_CELLS => 'FALSE', D
ATA_BLOCK_ENCODING => 'NONE', COMPRESSION => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', BLOCKCACHE => 'true
', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}                                                             

{NAME => 'info3', BLOOMFILTER => 'ROW', IN_MEMORY => 'false', VERSIONS => '1', KEEP_DELETED_CELLS => 'FALSE', D
ATA_BLOCK_ENCODING => 'NONE', COMPRESSION => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', BLOCKCACHE => 'true
', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}                                                             

3 row(s)
Quota is disabled
Took 1.6924 seconds 

7. 删除列族

java 复制代码
# 删除hainiu_table 表的 cf3 列族
alter 'hainiu:info',{NAME=>'info',METHOD=>'delete'}
# 查看表结构
describe 'hainiu:info'
java 复制代码
hbase:001:0> alter 'hainiu:info',{NAME=>'info3',METHOD=>'delete'}
Updating all regions with the new schema...
1/1 regions updated.
Done.
Took 4.1782 seconds                                                                                            
hbase:002:0> describe 'hainiu:info'
Table hainiu:info is ENABLED                                                                                   
hainiu:info                                                                                                    
COLUMN FAMILIES DESCRIPTION                                                                                    
{NAME => 'info1', BLOOMFILTER => 'ROW', IN_MEMORY => 'false', VERSIONS => '1', KEEP_DELETED_CELLS => 'FALSE', D
ATA_BLOCK_ENCODING => 'NONE', COMPRESSION => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', BLOCKCACHE => 'true
', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}                                                             

{NAME => 'info2', BLOOMFILTER => 'ROW', IN_MEMORY => 'false', VERSIONS => '1', KEEP_DELETED_CELLS => 'FALSE', D
ATA_BLOCK_ENCODING => 'NONE', COMPRESSION => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', BLOCKCACHE => 'true
', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}                                                             

2 row(s)
Quota is disabled
Took 0.0695 seconds   

8. 其他ddl操作

java 复制代码
# 把表设置为disable(下线)
disable '表名'

# drop表
# 先把表下线,再drop表
disable '表名'
# 启动表
enable '表名'
drop '表名'  

# 判断表是否存在
exists '表名'

# 判断表是否下线
is_disabled '表名'

# 判断表是否上线
is_enabled '表名'
java 复制代码
hbase:003:0> create 'hainiu:student', 'name', 'age'
Created table hainiu:student
Took 1.3426 seconds                                                                                            
=> Hbase::Table - hainiu:student
hbase:004:0> disable 'hainiu:student'
Took 0.7914 seconds                                                                                            
hbase:005:0> drop 'hainiu:student'
Took 0.7322 seconds                                                                                            
hbase:006:0> list_namespace_tables 'hainiu'
TABLE                                                                                                          
info                                                                                                           
1 row(s)
Took 0.0437 seconds                                                                                            
=> ["info"]
-- 先下线表,才可以删除表
java 复制代码
hbase:001:0> exists 'hainiu:info'
Table hainiu:info does exist                                                                                   
Took 1.2314 seconds                                                                                            
=> true
hbase:002:0> is_disabled 'hainiu:info'
false                                                                                                          
Took 0.0261 seconds                                                                                            
=> false
相关推荐
天冬忘忧5 分钟前
Kafka 工作流程解析:从 Broker 工作原理、节点的服役、退役、副本的生成到数据存储与读写优化
大数据·分布式·kafka
SRC_BLUE_179 分钟前
SQLI LABS | Less-55 GET-Challenge-Union-14 Queries Allowed-Variation 2
oracle·c#·less
sevevty-seven38 分钟前
幻读是什么?用什么隔离级别可以防止幻读
大数据·sql
Yz98762 小时前
hive复杂数据类型Array & Map & Struct & 炸裂函数explode
大数据·数据库·数据仓库·hive·hadoop·数据库开发·big data
.3 小时前
接口 测试
数据库·oracle
那一抹阳光多灿烂3 小时前
Spark中的Stage概念
大数据·spark
EDG Zmjjkk4 小时前
Hive 函数(实例操作版2)
数据仓库·hive·hadoop
北京鹏生科技有限公司4 小时前
EcoVadis审核是什么?EcoVadis审核流程包括什么?
大数据·百度
Moshow郑锴5 小时前
数据库、数据仓库、数据湖、数据中台、湖仓一体的概念和区别
大数据·数据库·数据仓库·数据湖·湖仓一体
LIT-涛6 小时前
JavaEE初学07
数据库·oracle·java-ee