python3操作hive

python3操作hive用官网开发的impyla包

Centos7安装Python3

参考: https://www.cnblogs.com/FZfangzheng/p/7588944.html

python3操作hive

参考: https://blog.csdn.net/suzyu12345/article/details/79456189

sudo yum install cyrus-sasl-devel
sudo yum install gcc-c++

服务器不能上网,用代理安装

pip3.5 install -i http://192.168.25.200/ali --trusted-host 192.168.25.200 thrift-sasl==0.2.1
pip3.5 install -i http://192.168.25.200/ali --trusted-host 192.168.25.200 sasl
pip3.5 install -i http://192.168.25.200/ali --trusted-host 192.168.25.200 impyla

示例:

#!/usr/bin/env python
#-*- encoding: utf8 -*-

from impala.dbapi import connect

# 需要注意的是这里的auth_mechanism必须有,但database不必须
conn = connect(host='192.168.81.201', port=10001, database='xy_dm' , user='xxx', password='xxx',auth_mechanism='PLAIN')
cur = conn.cursor()

cur.execute('SHOW DATABASES')
print(cur.fetchall())

cur.execute('SHOW Tables')
print(cur.fetchall())

cur.close()
conn.close()

您可以选择一种方式赞助本站