如何通过JDBC将mysql导入Clickhouse
1. 部署clickhouse-jdbc-bridge
clickhouse-jdbc-bridge是通过jdbc将Clickhouse与其他数据沟通的桥梁,可将其他数据库数据导入clickhouse中,也可以直接在clickhouse中访问其他数据库。
1.2 重新编译bridge
不想重新编译可以去官网下载
https://github.com/ClickHouse/clickhouse-jdbc-bridge/releases
git clone https://github.com/ClickHouse/clickhouse-jdbc-bridge.git
cd clickhouse-jdbc-bridge
mvn -Drevision=2.0.0 package
1.3 下载Microsoft JDBC驱动
把下载的驱动放到clickhouse-jdbc-bridge目录下的drivers子目录
本次JDBC版本为:phoenix-client-hbase-2.1-5.1.2.jar
注意:jdbc版本需与Ubuntu环境中的java版本一致
2. 配置clickhouse-jdbc-bridge
mkdir -p config/datasources #创建config目录及datasources子目录用于存放配置
新建 ckjdbc.json
{
"$schema": "../datasource.jschema",
"ckjdbc": {
"aliases": [
"self"
],
"driverUrls": [
"/server/hbase/drivers/phoenix-server-hbase-2.1-5.1.2.jar"
],
"driverClassName": "org.apache.phoenix.jdbc.PhoenixDriver",
"jdbcUrl": "jdbc:phoenix:101.34.236.169:2181:/hbase",
"username": "",
"password": "",
"maximumPoolSize": 5
}
}
如下 命名需要一致
3. 运行clickhouse-jdbc-bridge
cd target
java -jar clickhouse-jdbc-bridge-2.0.0.jar
#如果成功运行,会出现已加载的数据源信息,如前面的ckjdbc。
4. 使用clickhouse-jdbc-bridge迁移数据
4.1 先用DBeaver或clickhouse-client创建表
CREATE TABLE default.test2
(
`ID` Int32,
`NAME` String
)
ENGINE = JDBC('ckjdbc', 'WYS', 'TEST')
CREATE TABLE test3(id Int32, NAME String) ENGINE = MergeTree
ORDER BY id
SETTINGS index_granularity = 8192;
INSERT INTO test3 SELECT * FROM jdbc('ckjdbc', 'SELECT * FROM WYS.TEST');