微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

HBase操作

命令行操作

1.启动shell

hbase shell

2.帮助命令

help

3.数据库查看

list

4.创建新表

create 'student','info'

一个student可以理解为表名,也可以理解为是行名称,第二个参数是列簇名,列簇可以有多个,每个之间用顿号隔开

5.新增数据

put 'student','1001','info:sex','male'
put 'student','1001','age','18'
put 'student','1002','name','Janna'
put 'student','1002','info:sex','female'

6.扫描查看数据

scan 'student'
scan 'student', {STARTROW=>'1001',STOPROW=>'1002'}
scan 'student', {STARTROW=>'1001'}

7.查看表结构

describe 'student'

8.查看指定行或者指定列簇和列

get 'student','1001'
get 'student','1001','info:name'

9.统计数据行

count 'student'

10,删除数据

deleteall 'student','1001'
deleteall 'student','1002','info:sex'

11,清空数据

truncate 'student'

12,删除

disable 'student'
drop 'student'

13,变更表信息

alter 'student',{NAME=>'info',VERSIONS=>3}

pycharm连接hbase

1.开启thrift服务

hbase-daemons.sh start thrift

代码示例:

import happybase

connection = happybase.Connection('192.168.83.100')
connection.open() #打开传输

# 获取一个table对象
table = connection.table('sudent')
for key,value in table.scan():
    print(key,value)

结果:

D:\Anaconda3\install\envs\tensorflow\python.exe E:/learning/hbase_pycharm/main.py
b'1001' {b'info:age': b'20', b'info:sex': b'male'}
b'1002' {b'info:age': b'18', b'info:name': b'Janna'}

Process finished with exit code 0

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐