命令行操作
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