python连接hiveserver2
2017-10-25 13:11
603 查看
1.开启metastore和hiveserver2服务
$hive --service metastore &$hive --service hiveserver2 &
2.beeline调试,远程连接到HiveServer2
$cd /home/hdfs/project/hive-2.1.1/bin$./beeline
beeline> !connect jdbc:hive2://192.168.1.58:10000 hdfs hyxy123
报错: User: hdfs is not allowed to impersonate root (state=08S01,code=0)
3.停止集群和hive,修改配置,同步配置,重启集群和hive
$stop-all.shkill掉hive的两个进程
修改hadoop 配置文件 etc/hadoop/core-site.xml,加入如下配置项
<property>
<name>hadoop.proxyuser.root.hosts</name>
<value>*</value>
</property>
<property>
<name>hadoop.proxyuser.root.groups</name>
<value>*</value>
</property>
Hadoop.proxyuser.root.hosts配置项名称中root部分为报错User:* 中的用户名部分
例如User: hdfs is not allowed to impersonate anonymous则需要将xml变更为如下格式
<property>
<name>hadoop.proxyuser.hdfs.hosts</name>
<value>*</value>
</property>
<property>
<name>hadoop.proxyuser.hdfs.groups</name>
<value>*</value>
</property>
重启hadoop和hive
$start-all.sh
$hive --service metastore &
$hive --service hiveserver2 &
4.beeline再次调试
$cd /home/hdfs/project/hive-2.1.1/bin$./beeline
beeline> !connect jdbc:hive2://192.168.1.58:10000 hdfs hyxy123
0: jdbc:hive2://192.168.1.58:10000> show tables;
5.python连接hiveserver2代码
# -*- coding: utf-8 -*-
import pyhs2
import sys
default_encoding = 'utf-8'
if sys.getdefaultencoding() != default_encoding:
reload(sys)
sys.setdefaultencoding(default_encoding)
class HiveClient:
def __init__(self,db_host,user,password,database,port=10008,authMechanism="PLAIN"):
"""
create connection to hive server2
"""
self.conn = pyhs2.connect(host=db_host,
port=port,
authMechanism=authMechanism,
user=user,
password=password,
database=database,)
def query(self, sql):
"""
query
"""
with self.conn.cursor() as cursor:
cursor.execute(sql)
return cursor.fetch()
def close(self):
"""
close connection
"""
self.conn.close()
if __name__ == '__main__':
hive_client = HiveClient(db_host='127.0.0.1',port=10000,user='hdfs',password='hyxy123',database='default', authMechanism='PLAIN')
sql = "show tables"
result = hive_client.query(sql)
print result
hive_client.close()
相关文章推荐
- 【数据平台】基于pyhs2库Python作为client driver连接HiveServer
- linux服务器上cloudera:cdh5.8使用python连接hiveServer2
- Python连接到HiveServer2
- python连接hiveserver2
- python连接hiveserver2
- ambari离线方式安装Hive不能连接mysql和不能启动hive metastore&hiveserver2
- HiveServer2 ZooKeeper 连接泄漏
- hive语句嵌入python脚本(进行map和reduce,实现左外连接)
- The Ex CS Grad Student: Running HQL from Python without using the Hive Standalone Server
- Java代码通过JDBC连接Hiveserver2
- Hive中文乱码(JDBC连接HiveServer2)问题解决
- ubuntu16.04+hadoop2.7.2+hive1.2.1 server2通过jdbc连接
- hive语句嵌入python脚本(进行map和reduce,实现左外连接)
- hadoop组件---数据仓库(五)---通过JDBC连接hive的thrift或者hiveserver2
- python守护进程监控hive server
- java jdbc 连接hive cdh4.2 hiveserver2
- 几个连接HiveServer的客户端界面工具
- 解决beeline 不能连接 hiveserver2的问题
- Running HQL from Python without using the Hive Standalone Server
- 几个连接HiveServer的客户端界面工具