2 启动hive 的thrift
确保以下服务开启:
hive --service hiveserver
默认端口是10000
from hive_service import thrifthive from thrift import thrift from thrift.transport import tsocket from thrift.transport import ttransport from thrift.protocol import tbinaryprotocol def readhivetest(sql): try: tsocket = tsocket.tsocket('172.18.1.88',10000) ttransport = ttransport.tbufferedtransport(tsocket) protocol = tbinaryprotocol.tbinaryprotocol(ttransport) client = thrifthive.client(protocol) ttransport.open() client.execute(sql) return client.fetchall() except thrift.texception, tx: print '%s' % (tx.message) finally: ttransport.close() if __name__ == '__main__': showdatabasessql = 'show databases' showtablessql = 'show tables' selectsql = 'select * from 07_jn_mysql_2' result = readhivetest(selectsql) print(result[1])
以上就是python如何连接和启动hive的详细内容。
