第一次尝试用Python连接clickhouse数据库,踩了不少坑,特此记录,帮助后人少犯错!
运行环境:
- python 3.8.3
- clickhouse_driver==0.2.3
- clickhouse_sqlalchemy==0.2.0
- sqlalchemy==1.4.32
clickhouse_driver连接的两种方式
1.Client
借鉴网上的方法
from clickhouse_driver import Client
client = Client(host=host, port=8123, database=database,user=user ,password=pw)
sql = 'SHOW TABLES'
res = client.execute(sql)
报错:UnexpectedPacketFromServerError: Code: 102
原因:端口问题,HTTP协议(默认端口8123);TCP (Native)协议(默认端口号为9000),Python里的clickhouse_driver用的tcp端口9000,DBeaver使用的是HTTP协议所以可以使用8123端口。
修改后<
2万+



被折叠的 条评论
为什么被折叠?



