【大数据学习 | 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
相关推荐
javachen__1 小时前
SpringBoot整合P6Spy实现全链路SQL监控
spring boot·后端·sql
一只栖枝5 小时前
华为 HCIE 大数据认证中 Linux 命令行的运用及价值
大数据·linux·运维·华为·华为认证·hcie·it
喂完待续9 小时前
Apache Hudi:数据湖的实时革命
大数据·数据仓库·分布式·架构·apache·数据库架构
青云交9 小时前
Java 大视界 -- 基于 Java 的大数据可视化在城市交通拥堵治理与出行效率提升中的应用(398)
java·大数据·flink·大数据可视化·拥堵预测·城市交通治理·实时热力图
武昌库里写JAVA11 小时前
JAVA面试汇总(四)JVM(一)
java·vue.js·spring boot·sql·学习
老虎062712 小时前
数据库基础—SQL语句总结及在开发时
数据库·sql·oracle
Mr. zhihao15 小时前
SQL LEFT JOIN 与 WHERE 条件的隐藏坑
数据库·sql
还是大剑师兰特15 小时前
Flink面试题及详细答案100道(1-20)- 基础概念与架构
大数据·flink·大剑师·flink面试题
silver988616 小时前
sql链接的url中serverTimezone的作用
数据库·sql
sleetdream18 小时前
Flink Sql 按分钟或日期统计数据量
sql·flink