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

相关文章

超详细的记录了HBase 集群搭建的整个过程,以及搭建过程出现...
头歌 HBase(相关的五个实验)
1.创建一个学生信息表,用来存储学生的姓名(姓名作为行键,...
大数据课程综合实验案例1 案例简介1.1 案例目的1.2 适用对象...
HBase从浅入深,(初级)什么是HBase,模型,NOSQL,架构,n...
Hadoop之Hbase安装和配置