CentOs安装pyhive
生活随笔
收集整理的這篇文章主要介紹了
CentOs安装pyhive
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
yum install gcc-c++ python-devel.x86_64 cyrus-sasl-devel.x86_64
?
pip install sasl
pip install thrift
pip install thrift-sasl
pip install PyHive
?
以下為代碼demo,功能是打印出所有表的建表語句。代碼中連接的hive使用的LDAP驗證方式,所以設(shè)置了用戶名和密碼。
import os import sys reload(sys) sys.setdefaultencoding('utf8') from pyhive import hiveusername = your user name password = your pwd#database = 'test' #dir_name = '/home/lwx/data/'+'dw'+'.sql'cnn=hive.Connection(host='your ip add', port='10000',auth='LDAP',username = username,password = password ) cursor=cnn.cursor() dbs = ['test1','test2','test3']for db in dbs:cursor.execute("show tables in %s"%(db))for table in cursor.fetchall():cursor.execute("show create table %s.%s"%(db,table[0]))for i in cursor.fetchall():print str(i[0])如果沒有設(shè)置驗證方式,如下
import os import sys reload(sys) sys.setdefaultencoding('utf8') from pyhive import hivecnn=hive.Connection(host='your ip add', port='10000',username = username ) #connection中也可以指定db cursor=cnn.cursor() dbs = ['test1','test2','test3']for db in dbs:cursor.execute("show tables in %s"%(db))for table in cursor.fetchall():cursor.execute("show create table %s.%s"%(db,table[0]))for i in cursor.fetchall():print str(i[0]) # print or other operations~add : 2019-10-22
安裝sasl遇到錯誤 :??error: sasl/sasl.h: No such file or directory
解決:?yum -y install cyrus-sasl cyrus-sasl-devel cyrus-sasl-lib
?
?
總結(jié)
以上是生活随笔為你收集整理的CentOs安装pyhive的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: CodeBlocks 20.03 开发基
- 下一篇: 机器学习数据预处理之字符串转数字