从clickhouse导出数据

kqhtkvqz  于 2021-07-15  发布在  ClickHouse
关注(0)|答案(2)|浏览(732)

请建议使用python从clickhouse导出数据的最佳方法。
现在我正在使用此代码,但有一个错误,说明无法访问hotsname。

from clickhouse_driver import Client
client=Client(host='http://ipaddress',user='user',password='pass',port=8123)
print(client.execute('select * from table limit 5'))

还有别的办法吗?

sshcrbum

sshcrbum1#

在您提供的代码示例中,

from clickhouse_driver import Client
client=Client(host='http://ipaddress',user='user',password='pass',port=8123)
print(client.execute('select * from table limit 5'))

你把 http://ipaddress 不是有效的主机名,如果您将其更改为有效的主机名,它应该可以正常工作。

rkttyhzu

rkttyhzu2#

clickhouse驱动程序通过本机协议而不是http与clickhouse通信,因此:
主机应包含主机名或ip(不是http url)
端口应为9000(或9440用于安全连接)
我将依赖生成器函数execute iter来传输导出数据:

from clickhouse_driver import Client

client = Client(host='localhost')

data = client.execute_iter('SELECT * FROM numbers(1 * 1000 * 1000)')
row_count = 0

for row in data:
    # do smth per row
    row_count += 1

print(f"Row count is {row_count}.")

# Row count is 1000000.

相关问题