使用python把mysql数据导入到clickhouse

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)

你可能感兴趣的:(bigdata)