【大数据学习 | 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
相关推荐
Hacker_LaoYi1 小时前
SQL注入的那些面试题总结
数据库·sql
Hacker_LaoYi3 小时前
【渗透技术总结】SQL手工注入总结
数据库·sql
独行soc3 小时前
#渗透测试#漏洞挖掘#红蓝攻防#护网#sql注入介绍06-基于子查询的SQL注入(Subquery-Based SQL Injection)
数据库·sql·安全·web安全·漏洞挖掘·hw
Data跳动4 小时前
Spark内存都消耗在哪里了?
大数据·分布式·spark
独行soc5 小时前
#渗透测试#漏洞挖掘#红蓝攻防#护网#sql注入介绍08-基于时间延迟的SQL注入(Time-Based SQL Injection)
数据库·sql·安全·渗透测试·漏洞挖掘
woshiabc1115 小时前
windows安装Elasticsearch及增删改查操作
大数据·elasticsearch·搜索引擎
百度智能云技术站5 小时前
广告投放系统成本降低 70%+,基于 Redis 容量型数据库 PegaDB 的方案设计和业务实践
数据库·redis·oracle
lucky_syq5 小时前
Saprk和Flink的区别
大数据·flink
lucky_syq5 小时前
流式处理,为什么Flink比Spark Streaming好?
大数据·flink·spark
袋鼠云数栈5 小时前
深入浅出Flink CEP丨如何通过Flink SQL作业动态更新Flink CEP作业
大数据