使用python把mysql数据导入到clickhouse

版权声明:使用中有任何问题,可以留言,能解答尽量解答。交流q群773718900 https://blog.csdn.net/liyyzz33/article/details/90903359

clickhouse_driver python
第三方库下载地址:
https://github.com/mymarilyn/clickhouse-driver
https://pypi.org/project/clickhouse-driver/0.0.3/

from clickhouse_driver import Client

client = Client("clickhouse_server_ip", "9000", "db", "tables", "")
###直接插入到clickhouse现有表testtable
sql = """
insert into testtable SELECT * FROM mysql('dbip:3306', 'testDB', 'testtable', 'root', 'passwd')
"""
print(sql)
try:
    client.execute(sql, types_check=True)
except Exception as e:
    print(e)
###mysql数据表插入到clickhouse的创建新表
# sql = """
# CREATE TABLE testtable ENGINE = MergeTree ORDER BY id AS SELECT * FROM mysql('192.168.1.2:3306', 'testtable', 'testtable_001', 'root', 'passwd')"""
# print(sql)
# try:
#     client.execute(sql, types_check=True)
# except Exception as e:
#     print(e)

猜你喜欢

转载自blog.csdn.net/liyyzz33/article/details/90903359