Python連接hive,我使用pyhive孽鸡。
以下安裝流程如下:
1蹂午、創(chuàng)建虛擬環(huán)境(也可以不用創(chuàng)建栏豺,但建議創(chuàng)建安裝):
conda create -n hiveconn python=3.6
2、進(jìn)入虛擬環(huán)境下: conda activate hiveconn
3豆胸、使用conda安裝以下兩個(gè)包奥洼,如果用pip會(huì)失敗:
conda install sasl
conda install thrift_sasl
4、安裝pip install thrift
晚胡,以及pip install PyHive
安裝成功
下面如果用Python連接hive灵奖,代碼如下:
from pyhive import hive
conn = hive.Connection(host='10.10.10.88', port=8008, username='***', password='*******', database='數(shù)據(jù)庫名稱', auth="CUSTOM")
cursor = conn.cursor()
cursor.execute('select * from Table')
for result in cursor.fetchall():
print(result)