09-13-Hbase-shell入门操作

6 篇文章 0 订阅

09-Hbase-shell入门操作:

HBase Shell 操作

DDL基本操作

1.进入 HBase 客户端命令行

[root@hadoop102 hbase-1.3.1]# bin/hbase shell

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-wXnfGn8i-1669555190416)(png/1617594832289.png)]

2.查看帮助命令

hbase(main):001:0> help

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-dFF0Ob2U-1669555190417)(png/1617594883331.png)]

3.查看当前数据库中有哪些表

hbase(main):002:0> list

创建表

hbase(main):005:0> create ‘student’,‘info’
hbase(main):007:0> create ‘stu’,‘info1’,‘info2’
hbase(main):008:0> list
TABLE
stu
student

=> [“stu”, “student”]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-HOFpiRxS-1669555190417)(png/1617596673878.png)]

查看表信息

hbase(main):009:0> describe ‘stu’

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-wylj6gss-1669555190418)(png/1617596740139.png)]

更改表信息

hbase(main):012:0> alter ‘student’,{NAME=>‘info’,VERSIONS=>3}

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-16XCGvJh-1669555190418)(png/1617596789121.png)]

删除表

hbase(main):014:0> drop ‘student’

ERROR: Table student is enabled. Disable it first.

Here is some help for this command:
Drop the named table. Table must first be disabled:
hbase> drop ‘t1’
hbase> drop ‘ns1:t1’

hbase(main):015:0> disable ‘student’
0 row(s) in 3.0520 seconds

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-cAtxl1mA-1669555190419)(png/1617596278472.png)]

hbase(main):016:0> drop ‘student’
0 row(s) in 3.0470 seconds

hbase(main):017:0> list

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-vWMIWVwk-1669555190419)(png/1617596824431.png)]

命名空间:

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-4IKB6i4u-1669555190420)(png/1618234941326.png)]

创建命名空间

hbase(main):004:0> create ‘bigdata:stu’,“info”
hbase(main):005:0> list

删除命名空间

hbase(main):006:0> drop_namespace ‘bigdata’

ERROR: org.apache.hadoop.hbase.constraint.ConstraintException: Only empty namespaces can be removed. Namespace bigdata has 1 tables
Drop the named namespace. The namespace must be empty.

hbase(main):007:0> disable ‘bigdata:stu’

hbase(main):008:0> drop ‘bigdata:stu’
hbase(main):009:0> drop_namespace ‘bigdata’

hbase(main):010:0> list

DML基本操作(重)

增加

hbase> put ‘ns1:t1’, ‘r1’, ‘c1’, ‘value’

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-8mAZL1a9-1669555190421)(png/1618235608289.png)]

hbase(main):002:0> scan ‘stu’
ROW COLUMN+CELL
1001 column=info1:name, timestamp=1618235653696, value=zhangsan
1 row(s) in 1.4550 seconds

ghbase(main):002:0> get

ghbase(main):002:0> get ‘stu’,‘1001’

hbase(main):003:0> put ‘stu’,‘1001’,‘info1:sex’,‘male’

hbase(main):004:0> put ‘stu’,‘1001’,‘info2:addr’,‘shanghai’

hbase(main):005:0> put ‘stu’,‘1002’,‘info1:name’,‘lisi’

hbase(main):006:0> put ‘stu’,‘1002’,‘info1:phone’,‘18332456666’

hbase(main):007:0> put ‘stu’,‘1003’,‘info2:addr’,‘beijing’

hbase(main):008:0> scan ‘stu’

hbase(main):009:0> get ‘stu’,‘1001’

hbase(main):010:0> get ‘stu’,‘1001’,‘info1:name’

hbase(main):011:0> get ‘stu’,‘1001’,‘info1’

hbase(main):012:0> scan ‘stu’,{STARTROW=>‘1001’,STOPROW=>‘1003’}//左闭右开

hbase(main):013:0> scan ‘stu’,{STARTROW=>‘1001’}=10’,‘info1:name’,‘xiaohong’

hbase(main):014:0> put ‘stu’,‘10010’,‘info1:name’,‘xiaohong’
0 row(s) in 0.4240 seconds

hbase(main):015:0> scan ‘stu’,{STARTROW=>‘1001’}//注意顺序

hbase(main):002:0> put ‘stu’,‘1001’,‘info1:name’, ‘zangsan02’

hbase(main):003:0> scan ‘stu’
ROW COLUMN+CELL

1001 column=info1:name, timestamp=1618237274701, value=zangsan02

1001 column=info1:sex, timestamp=1618235992343, value=male
1001 column=info2:addr, timestamp=1618236016442, value=shanghai
10010 column=info1:name, timestamp=1618236476571, value=xiaohong
1002 column=info1:name, timestamp=1618236039169, value=lisi
1002 column=info1:phone, timestamp=1618236064087, value=18332456666
1003 column=info2:addr, timestamp=1618236088958, value=beijing
4 row(s) in 0.0670 seconds

hbase(main):004:0> scan ‘stu’,{RAW=>true,VERSIONS=>10}
ROW COLUMN+CELL

1001 column=info1:name, timestamp=1618237274701, value=zangsan02
1001 column=info1:name, timestamp=1618235653696, value=zhangsan

1001 column=info1:sex, timestamp=1618235992343, value=male
1001 column=info2:addr, timestamp=1618236016442, value=shanghai
10010 column=info1:name, timestamp=1618236476571, value=xiaohong
1002 column=info1:name, timestamp=1618236039169, value=lisi
1002 column=info1:phone, timestamp=1618236064087, value=18332456666
1003 column=info2:addr, timestamp=1618236088958, value=beijing
4 row(s) in 0.2650 seconds

hbase(main):007:0> put ‘stu’,‘1001’,‘info1:name’,‘zangsan03’,1618235653670

hbase(main):008:0> get ‘stu’,‘1001’,‘info1:name’
COLUMN CELL
info1:name timestamp=1618237274701, value=zangsan02

hbase(main):010:0> scan ‘stu’,{RAW=>true,VERSIONS=>10}
ROW COLUMN+CELL
1001 column=info1:name, timestamp=1618237274701, value=zangsan02
1001 column=info1:name, timestamp=1618235653696, value=zhangsan
1001 column=info1:name, timestamp=1618235653670, value=zangsan03

删除(以时间戳最大返回)

hbase(main):001:0> delete ‘stu’,‘1001’,‘info1:sex’

hbase(main):002:0> scan ‘stu’ //扫描表

hbase(main):003:0> delete ‘stu’,‘1001’,‘info1:name’ //删除列

hbase(main):004:0> scan ‘stu’,{RAW=>true,VERSIONS=>10}//扫描全部版本

hbase(main):005:0> deleteall //deleteall的用法

hbase(main):006:0> deleteall ‘stu’,‘1003’

hbase(main):008:0> truncate ‘stu’ //删除表
Truncating ‘stu’ table (it may take a while):

  • Disabling table…
  • Truncating table…
    0 row(s) in 12.5740 seconds

hbase(main):009:0> scan ‘stu’
ROW COLUMN+CELL
0 row(s) in 1.0580 seconds

版本VERSIONS的初步理解(hbase以后最大的保存的版本数量)

hbase(main):013:0> create ‘stu2’,‘info’
hbase(main):014:0> put ‘stu2’,‘1005’,‘info:name’,‘lisi’

hbase(main):015:0> put ‘stu2’,‘1005’,‘info:name’,‘zhangsan’
0 row(s) in 0.0270 seconds

hbase(main):016:0> alert ‘stu2’,{NAME=>‘info’,VERSIONS=>2}
NoMethodError: undefined method `alert’ for #Object:0x46fb0c33

hbase(main):017:0> alter ‘stu2’,{NAME=>‘info’,VERSIONS=>2}
Updating all regions with the new schema…
0/1 regions updated.
1/1 regions updated.
Done.
0 row(s) in 4.3310 seconds

hbase(main):018:0> put ‘stu2’,‘1001’,‘info:name’,‘zhangsan’
0 row(s) in 0.0190 seconds

hbase(main):019:0> put ‘stu2’,‘1001’,‘info:name’,‘lisi’
0 row(s) in 0.0110 seconds

hbase(main):020:0> get ‘stu2’,‘1001’,{COLUMN=>‘info:name’,VERSIONS=>3}
COLUMN CELL
info:name timestamp=1618239366717, value=lisi
info:name timestamp=1618239356363, value=zhangsan
0> get ‘stu2’,‘1001’,{COLUMN=>‘info:name’,VERSIONS=>3}
COLUMN CELL
info:name timestamp=1618239366717, value=lisi
info:name timestamp=1618239356363, value=zhangsan
1 row(s) in 0.0200 seconds

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值