Help wanted!
The following content of this documentation page has been machine-translated. But unlike other websites, it is not done on the fly. This translated text lives on GitHub repository alongside main ClickHouse codebase and waits for fellow native speakers to make it more human-readable. You can also use the original English version as a reference.
JDBC
Permet à ClickHouse de se connecter à des bases de données externes via JDBC.
Pour implémenter la connexion JDBC, ClickHouse utilise le programme séparé clickhouse-JDBC-pont cela devrait fonctionner comme un démon.
Ce moteur prend en charge le Nullable type de données.
Création d'une Table
CREATE TABLE [IF NOT EXISTS] [db.]table_name
(
columns list...
)
ENGINE = JDBC(dbms_uri, external_database, external_table)
Les Paramètres Du Moteur
-
dbms_uri
— URI of an external DBMS.Format:
jdbc:<driver_name>://<host_name>:<port>/?user=<username>&password=<password>
.
Exemple pour MySQL:jdbc:mysql://localhost:3306/?user=root&password=root
. -
external_database
— Database in an external DBMS. -
external_table
— Name of the table inexternal_database
.
Exemple D'Utilisation
Création d'une table dans le serveur MySQL en se connectant directement avec son client console:
mysql> CREATE TABLE `test`.`test` (
-> `int_id` INT NOT NULL AUTO_INCREMENT,
-> `int_nullable` INT NULL DEFAULT NULL,
-> `float` FLOAT NOT NULL,
-> `float_nullable` FLOAT NULL DEFAULT NULL,
-> PRIMARY KEY (`int_id`));
Query OK, 0 rows affected (0,09 sec)
mysql> insert into test (`int_id`, `float`) VALUES (1,2);
Query OK, 1 row affected (0,00 sec)
mysql> select * from test;
+------+----------+-----+----------+
| int_id | int_nullable | float | float_nullable |
+------+----------+-----+----------+
| 1 | NULL | 2 | NULL |
+------+----------+-----+----------+
1 row in set (0,00 sec)
Création d'une table dans le serveur ClickHouse et sélection des données:
CREATE TABLE jdbc_table
(
`int_id` Int32,
`int_nullable` Nullable(Int32),
`float` Float32,
`float_nullable` Nullable(Float32)
)
ENGINE JDBC('jdbc:mysql://localhost:3306/?user=root&password=root', 'test', 'test')
SELECT *
FROM jdbc_table
┌─int_id─┬─int_nullable─┬─float─┬─float_nullable─┐
│ 1 │ ᴺᵁᴸᴸ │ 2 │ ᴺᵁᴸᴸ │
└────────┴──────────────┴───────┴────────────────┘