centos7中python访问hbase
时间: 2023-09-11 19:06:34 浏览: 168
在CentOS 7中访问HBase需要安装HBase的Python库 `happybase`。
下面是安装步骤:
1. 安装依赖包:
```bash
sudo yum install -y gcc python-devel cyrus-sasl-devel openssl-devel
```
2. 安装 `happybase`:
```bash
sudo pip install happybase
```
3. 在Python中连接HBase:
```python
import happybase
# 建立连接
connection = happybase.Connection('hbase-host', port=9090)
# 列出所有表
tables = connection.tables()
print(tables)
# 获取表
table = connection.table('mytable')
# 插入数据
table.put(b'row-key', {b'family:qual1': b'value1',
b'family:qual2': b'value2'})
# 获取数据
row = table.row(b'row-key')
print(row[b'family:qual1']) # b'value1'
# 扫描数据
for key, data in table.scan():
print(key, data)
```
替换 `hbase-host` 为实际的HBase主机名或IP地址。注意,HBase需要运行并且端口号为9090才能建立连接。
阅读全文
相关推荐















