ODBC

    To safely implement ODBC connections, ClickHouse uses a separate program . If the ODBC driver is loaded directly from clickhouse-server, driver problems can crash the ClickHouse server. ClickHouse automatically starts clickhouse-odbc-bridge when it is required. The ODBC bridge program is installed from the same package as the clickhouse-server.

    This engine supports the Nullable data type.

    See a detailed description of the query.

    • Column names should be the same as in the source table, but you can use just some of these columns and in any order.
    • Column types may differ from those in the source table. ClickHouse tries to cast values to the ClickHouse data types.

    Engine Parameters

    • connection_settings — Name of the section with connection settings in the odbc.ini file.
    • external_database — Name of a database in an external DBMS.
    • external_table — Name of a table in the external_database.

    Retrieving data from the local MySQL installation via ODBC

    This example is checked for Ubuntu Linux 18.04 and MySQL server 5.7.

    By default (if installed from packages), ClickHouse starts as user clickhouse. Thus, you need to create and configure this user in the MySQL server.

    1. $ sudo mysql
    1. mysql> CREATE USER 'clickhouse'@'localhost' IDENTIFIED BY 'clickhouse';
    2. mysql> GRANT ALL PRIVILEGES ON *.* TO 'clickhouse'@'clickhouse' WITH GRANT OPTION;

    Then configure the connection in /etc/odbc.ini.

    You can check the connection using the utility from the unixODBC installation.

    1. $ isql -v mysqlconn
    2. | Connected! |
    3. | |
    4. ...
    1. mysql> CREATE TABLE `test`.`test` (
    2. -> `int_id` INT NOT NULL AUTO_INCREMENT,
    3. -> `int_nullable` INT NULL DEFAULT NULL,
    4. -> `float` FLOAT NOT NULL,
    5. -> `float_nullable` FLOAT NULL DEFAULT NULL,
    6. -> PRIMARY KEY (`int_id`));
    7. Query OK, 0 rows affected (0,09 sec)
    8. mysql> select * from test;
    9. +--------+--------------+-------+----------------+
    10. | int_id | int_nullable | float | float_nullable |
    11. +--------+--------------+-------+----------------+
    12. | 1 | NULL | 2 | NULL |
    13. +--------+--------------+-------+----------------+
    14. 1 row in set (0,00 sec)

    Table in ClickHouse, retrieving data from the MySQL table:

    1. SELECT * FROM odbc_t
    1. ┌─int_id─┬─float_nullable─┐
    2. 1 ᴺᵁᴸᴸ
    3. └────────┴────────────────┘