clickhouse和mysql和pgsql在Jupyter上链接

本文详细介绍了使用Python连接和操作ClickHouse、MySQL及PostgreSQL数据库的方法。包括通过SQLAlchemy和pandas读取ClickHouse表,利用MySQLdb展示MySQL表,以及使用psycopg2执行和查询PostgreSQL语句的具体实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 clickhouse

from sqlalchemy.engine import create_engine
import pandas as pd
ch_engine=create_engine('clickhouse://172.xx.x.xx:8xxx/audience')

pd.read_sql('show tables',ch_engine)

mysql

import MySQLdb


mysql_conf = { 
    'host': '172.xx.x.x',
    'user': 'usersxx',
    'password': 'xxxx',
    'database': 'xxx',
    'charset': 'utf8'
}
mysql_engine = MySQLdb.connect(**mysql_conf)
sq1='''show tables;'''
df2=pd.read_sql(sq1,mysql_engine)
df2

 

pgsql

写执行的语句

import psycopg2
conn = psycopg2.connect(dbname='xxx', user='xxx', password='xxx', host='172.xx.xx.xx', port='xxxx')
cur = conn.cursor()
sql='copy ......'  # 写执行语句
cur.execute(sql)
conn.commit()

写查找的语句

import psycopg2
conn = psycopg2.connect(dbname='xxx', user='xxx', password='xxx', host='172.xx.xx.xx', port='xxxx')
cur = conn.cursor()
cur.execute('select xxx from xxx')
rows = cur.fetchall()

https://www.cnblogs.com/geo-will/p/9534732.html

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值