HBASE基本操作
在CMD上连接HBASE服务器:
hbase shell
注意:所有指令别带上分号
查看所有的表结构:
list
表删除操作: --disable --- drop
hbase的表创建后,便处于enable状态,标识正在使用,删除时,必须先让表处于disable,方可执行删除
hbase(main):0230:0>list
TABLE
KYLIN_EDW03TEXR7
kylin_metadata
2 row(s) in 0.0250 seconds
==> ["KYLIN_EDW03TEXR7", "kylin_metadata"]
hbase(main):0240:0>disable "KYLIN_EDW03TEXR7"
0 row(s) in 2.3250 seconds
hbase(main):0240:0>drop "KYLIN_EDW03TEXR7"
0 row(s) in 1.3250 seconds
退出连接:
!exit
hbase客户端
打开hbase 客户端,以下假定已经配置好环境变量
hbase shell
hbase中使用backspace无法删除时,使用以下方法替代:
ctrl + BackSpace
创建命名空间:testdata
create_namespace 'testdata'
查看命名空间
list_namespace
删除命名空间
drop_namespace 'testdata'
列出hbase上的所有表
list
列出命名空间testdata上的所有表
list_namespace_tables 'testdata'
创建一个表node_file_viruses,属于testdata命名空间,列族:cf1, cf2, cf3
create 'testdata:node_file_viruses', 'cf1', 'cf2', 'cf3'
4字节秒到2100年
4字节计数可以到42亿
rowkey: find_time(4) + id(4)
cf1: nid vlib_version virus_findby virus_op virus_type
cf2: virus_name
cf3: file_path task_id create_time
查看命名空间下的表的结构
describe 'testdata:node_file_viruses'
使用put插入数据:
常用语法: put '[namespacename:]tablename' , 'rowkey' , 'columnfamilyname[:column]' , 'value'
put 一次只能向一个单元格插入数据,以下是错误用法
put ‘testdata:node_file_viruses’, ’a1fac14100005f14’, 'cf1:nid',98314, 'cf1:vlib_version',45678, 'cf1:virus_findby',5, 'cf1:virus_op',1, 'cf1:virus_type',10, 'cf2:virus_name':'qazwsxedc', 'cf3:file_path':'/lovelsl/1abc', 'cf3:task_id':'12345678', 'cf3:task_id':'2019-12-01 07:33:32'
find_time = 1577402046
id = 24340
row = ((0xFFFFFFFF - 1577402046) << (8*4)) + (24340)
= 0xa1fac14100005f14
以下为正确方法:
put 'testdata:node_file_viruses', 'a1fac14100005f14', 'cf1:nid',98314
put 'testdata:node_file_viruses', 'a1fac14100005f14', 'cf1:vlib_version',45678
put 'testdata:node_file_viruses', 'a1fac14100005f14', 'cf1:virus_findby',5
put 'testdata:node_file_viruses', 'a1fac14100005f14', 'cf1:virus_op',1
put 'testdata:node_file_viruses', 'a1fac14100005f14', 'cf1:virus_type',10
put 'testdata:node_file_viruses', 'a1fac14100005f14', 'cf2:virus_name', 'qazwsxedc'
put 'testdata:node_file_viruses', 'a1fac14100005f14', 'cf3:file_path', '/lovelsl/1abc'
put 'testdata:node_file_viruses', 'a1fac14100005f14', 'cf3:task_id', '12345678'
put 'testdata:node_file_viruses', 'a1fac14100005f14', 'cf3:task_id', '2019-12-01 07:33:32'
使用get查询数据:
语法:get '[namespacename:]tablename' , 'rowkey' [, 'columnfamliyname[:column]']
get 'testdata:node_file_viruses', 'a1fac14100005f14'
删除一条记录
deleteall 'testdata:node_file_viruses', 'a1fac14100005f14'
删除一条记录中的部分内容
delete 'testdata:node_file_viruses', 'a1fac14100005f14', 'cf1:virus_op',1
查全表数据:
scan 'testdata:node_file_viruses'
对于无命名空间的表,直接scan即可:
如: scan 'node_file_viruses'
删除表
disable 'testdata:node_file_viruses'
drop 'testdata:node_file_viruses'
验证表是否被删除
exists 'testdata:node_file_viruses'

浙公网安备 33010602011771号