Python clickhouse_client 连接远程ck server

import sshtunnel as sshtunnel
from clickhouse_driver import connect

server= sshtunnel.SSHTunnelForwarder(
    ('**.***.**.75', 22),
    ssh_username="root",
    ssh_password="****",
    remote_bind_address=('localhost', 9000))
server.start()

local_port = server.local_bind_port
print(local_port)
# clickhouse//用户名:密码@ip:端口/数据库
conn = connect(f'clickhouse://default:clickhouse@localhost:{local_port}/default')
#conn = connect(host='localhost', port=local_port, database='ertb', user='default', password='')

cursor = conn.cursor()
cursor.execute('SHOW TABLES')
print(cursor.fetchall())

你可能感兴趣的:(clickhouse,Python,python,ssh,服务器)