第一种方式
import requests
SSL_VERIFY = False
host = 'http://127.0.0.1:8123'
db = '数据库名称'
table = '表名'
#插入
query_dict = {
'query': "insert into 数据库名称.表名(api,param,create_time,time) values('python-api','参数',now(),11)"
}
#查询
query_dict = {
'query': "select * from 数据库名称.表名"
}
r = requests.post(host,params=query_dict, verify=SSL_VERIFY)
print(r.text)
第二种方式
安装驱动
pip install clickhouse_driver
编码
from clickhouse_driver import connect
conn = connect('clickhouse://127.0.0.1:8123')
cursor = conn.cursor()
data = cursor.execute('select * from 数据库.表')
print(data)
clickhouse-driver
|