美文网首页
python 操作 clickhouse 连接 增 删 改 查

python 操作 clickhouse 连接 增 删 改 查

作者: 西贝巴巴 | 来源:发表于2020-10-10 15:48 被阅读0次
一、python 连接clickhouse

1.先导入clickhouse包:pip install clickhouse_driver
2.连接方式

from clickhouse_driver import Client
host='host_name' #服务器地址
port =3306 #端口
user='user' #用户名
password='password' #密码
database='database' #数据库
send_receive_timeout = 5 #超时时间
client = Client(host=host, port=port, user=user, password=password,database=database, send_receive_timeout=send_receive_timeout)
二、clickhouse 操作

1.查询

sql = 'select count(*) from tb_test '
ans = client.execute(sql)
print(ans)

2.插入

sql = 'INSERT INTO tb_test (t1,t2,t3) VALUES (1,2,3)'
ans = client.execute(sql)
print(ans)

3.删除

sql="truncate table cdm_dwd.dwd_ord_car_sharing_df on cluster crm_4shards_1replicas"
ans = client.execute(sql)
print(ans)

4.修改

alter table summer_cn.bi_ime_sale_history update sale_date = toDateTime('2020-03-31 00:00:00')  where id in (
'IDVIVO_sale1245122',
'IDVIVO_sale1245174',
'IDVIVO_sale1245233',
'IDVIVO_sale1245173');

相关文章

网友评论

      本文标题:python 操作 clickhouse 连接 增 删 改 查

      本文链接:https://www.haomeiwen.com/subject/jucjpktx.html