数据库的连接(mysql、clickhouse)

连接MySQL数据库(pymysql):

import pymysql

conn = pymysql.connect(host='地址',
                       port=3306,
                       user='账号',
                       passwd='密码',
                       charset='utf8'
                       )
#建立游标
cursor = conn.cursor()
#运行sql脚本
cursor.execute(sql)

连接到clikhouse

from clickhouse_driver import Client
host_name = '地址'
client = Client(host = host_name,
                # database = '数据库',
                user = '账号',
                password = '密码',
                port=9000)
client.execute(selsql)

猜你喜欢

转载自blog.csdn.net/qq_41110377/article/details/128733186