python连接hive
1.安装库:
pip install impyla
pip install thrift==0.9.3
pip install thrift_sasl #安装失败就要先安装依赖包:sudo yum install cyrus-sasl-devel
2.导入库
from impala.dbapi import connect
3.创建连接与游标对象
conn = connect(host="slave的ip",user="root",password='虚拟机密码',auth_mechanism="PLAIN",port=10000,database="hive中已有的数据库")
cur = conn.cursor() # 创建游标对象
cur.execute(sql) #执行sql语句
data = cur.fetchall() # 将执行完毕的sql语句的结果返回
注意:你的windows可能不兼容sasl,本人已踩坑,所以不建议使用pyhive进行操作