首先安装pyhive
pip install pyhive
连接hive通过LDAP
connection = hive.connect(host='HIVE_HOST',
port=10000,
database='temp',
username='HIVE_USERNAME',
password='HIVE_PASSWORD',
auth='CUSTOM')
连接hive通过Kerberos
from pyhive import hive
connection = hive.connect(host='HIVE_HOST',
port=10000,
database='temp',
username='HIVE_USERNAME',
auth='KERBEROS',
kerberos_service_name='hive')
执行hive查询
query="select * from temp.test_table"
cur = connection.cursor()
cur.execute(query)
res = cur.fetchall()