mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-17 05:03:20 +00:00
dba72d73fe
* enbaskakova-DOCSUP-652 (#101)
* "docs(orNull&orDefault): Functions 'orNull&orDefault' have been edited"
* "docs(orNull&orDefault): Functions 'orNull&orDefault' have been edited"
* "docs(orNull&orDefault): Functions 'orNull&orDefault' have been edited"
* Update docs/en/sql_reference/aggregate_functions/combinators.md
Co-Authored-By: BayoNet <da-daos@yandex.ru>
* Update docs/en/sql_reference/aggregate_functions/combinators.md
Co-Authored-By: BayoNet <da-daos@yandex.ru>
* Update docs/en/sql_reference/aggregate_functions/combinators.md
Co-Authored-By: BayoNet <da-daos@yandex.ru>
* Update docs/en/sql_reference/aggregate_functions/combinators.md
Co-Authored-By: BayoNet <da-daos@yandex.ru>
* Update docs/en/sql_reference/aggregate_functions/combinators.md
Co-Authored-By: BayoNet <da-daos@yandex.ru>
* "docs(orNull&orDefault): Functions 'orNull&orDefault' have been edited"
* "docs(orNull&orDefault): Functions 'orNull&orDefault' have been edited"
* "docs(orNull&orDefault): Functions 'orNull&orDefault' have been edited"
Co-authored-by: elenbaskakova <elenbaskakova@yandex-team.ru>
Co-authored-by: BayoNet <da-daos@yandex.ru>
* Revert "enbaskakova-DOCSUP-652 (#101)" (#107)
This reverts commit 639fee7610
.
* CLICKHOUSEDOCS-624: Fixed links. Was 60, became 13.
* CLICKHOUSEDOCS-624: Finished fix links in Enlish version.
* CLICKHOUSEDOCS-624: Fixed RU links
Co-authored-by: elenaspb2019 <47083263+elenaspb2019@users.noreply.github.com>
Co-authored-by: elenbaskakova <elenbaskakova@yandex-team.ru>
Co-authored-by: Sergei Shtykov <bayonet@yandex-team.ru>
88 lines
3.7 KiB
Markdown
88 lines
3.7 KiB
Markdown
# JDBC {#table-engine-jdbc}
|
||
|
||
Позволяет ClickHouse подключаться к внешним базам данных с помощью [JDBC](https://en.wikipedia.org/wiki/Java_Database_Connectivity).
|
||
|
||
Для реализации соединения по JDBC ClickHouse использует отдельную программу [clickhouse-jdbc-bridge](https://github.com/alex-krash/clickhouse-jdbc-bridge), которая должна запускаться как демон.
|
||
|
||
Движок поддерживает тип данных [Nullable](../../../engines/table-engines/integrations/jdbc.md).
|
||
|
||
## Создание таблицы {#sozdanie-tablitsy}
|
||
|
||
``` sql
|
||
CREATE TABLE [IF NOT EXISTS] [db.]table_name
|
||
ENGINE = JDBC(dbms_uri, external_database, external_table)
|
||
```
|
||
|
||
**Параметры движка**
|
||
|
||
- `dbms_uri` — URI внешней СУБД.
|
||
|
||
Формат: `jdbc:<driver_name>://<host_name>:<port>/?user=<username>&password=<password>`.
|
||
|
||
Пример для MySQL: `jdbc:mysql://localhost:3306/?user=root&password=root`.
|
||
|
||
- `external_database` — база данных во внешней СУБД.
|
||
|
||
- `external_table` — таблица в `external_database`.
|
||
|
||
## Пример использования {#primer-ispolzovaniia}
|
||
|
||
Создадим таблицу в на сервере MySQL с помощью консольного клиента MySQL:
|
||
|
||
``` text
|
||
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)
|
||
```
|
||
|
||
Создадим таблицу на сервере ClickHouse и получим из неё данные:
|
||
|
||
``` sql
|
||
CREATE TABLE jdbc_table ENGINE JDBC('jdbc:mysql://localhost:3306/?user=root&password=root', 'test', 'test')
|
||
```
|
||
|
||
``` sql
|
||
DESCRIBE TABLE jdbc_table
|
||
```
|
||
|
||
``` text
|
||
┌─name───────────────┬─type───────────────┬─default_type─┬─default_expression─┐
|
||
│ int_id │ Int32 │ │ │
|
||
│ int_nullable │ Nullable(Int32) │ │ │
|
||
│ float │ Float32 │ │ │
|
||
│ float_nullable │ Nullable(Float32) │ │ │
|
||
└────────────────────┴────────────────────┴──────────────┴────────────────────┘
|
||
```
|
||
|
||
``` sql
|
||
SELECT *
|
||
FROM jdbc_table
|
||
```
|
||
|
||
``` text
|
||
┌─int_id─┬─int_nullable─┬─float─┬─float_nullable─┐
|
||
│ 1 │ ᴺᵁᴸᴸ │ 2 │ ᴺᵁᴸᴸ │
|
||
└────────┴──────────────┴───────┴────────────────┘
|
||
```
|
||
|
||
## Смотрите также {#smotrite-takzhe}
|
||
|
||
- [Табличная функция JDBC](../../../engines/table-engines/integrations/jdbc.md).
|
||
|
||
[Оригинальная статья](https://clickhouse.tech/docs/ru/operations/table_engines/jdbc/) <!--hide-->
|