Skip to main content
Skip to main content

MySQL dictionary source

Example of settings:

SOURCE(MYSQL(
    port 3306
    user 'clickhouse'
    password 'qwerty'
    replica(host 'example01-1' priority 1)
    replica(host 'example01-2' priority 1)
    db 'db_name'
    table 'table_name'
    where 'id=10'
    invalidate_query 'SQL_QUERY'
    fail_on_connection_loss 'true'
    query 'SELECT id, value_1, value_2 FROM db_name.table_name'
    enable_compression 1
))

Setting fields:

SettingDescription
portThe port on the MySQL server. You can specify it for all replicas, or for each one individually (inside <replica>).
userName of the MySQL user. You can specify it for all replicas, or for each one individually (inside <replica>).
passwordPassword of the MySQL user. You can specify it for all replicas, or for each one individually (inside <replica>).
replicaSection of replica configurations. There can be multiple sections.
replica/hostThe MySQL host.
replica/priorityThe replica priority. When attempting to connect, ClickHouse traverses the replicas in order of priority. The lower the number, the higher the priority.
dbName of the database.
tableName of the table.
whereThe selection criteria. The syntax for conditions is the same as for WHERE clause in MySQL, for example, id > 10 AND id < 20. Optional.
invalidate_queryQuery for checking the dictionary status. Optional. Read more in the section Refreshing dictionary data using LIFETIME.
fail_on_connection_lossControls behavior of the server on connection loss. If true, an exception is thrown immediately if the connection between client and server was lost. If false, the server retries to fetch data at least three times before reporting an error. Note that retrying leads to increased response times. Default value: false.
queryThe custom query. Optional.
enable_compressionEnables zlib compression for the MySQL protocol connection. When set to 1, ClickHouse requests protocol-level compression from the MySQL server. Can also be set per-replica inside <replica>. Default value: 0.
Note

The table or where fields cannot be used together with the query field. And either one of the table or query fields must be declared.

Note

There is no explicit parameter secure. When establishing an SSL-connection security is mandatory.

MySQL can be connected to on a local host via sockets. To do this, set host and socket.

Example of settings:

SOURCE(MYSQL(
    host 'localhost'
    socket '/path/to/socket/file.sock'
    user 'clickhouse'
    password 'qwerty'
    db 'db_name'
    table 'table_name'
    where 'id=10'
    invalidate_query 'SQL_QUERY'
    fail_on_connection_loss 'true'
    query 'SELECT id, value_1, value_2 FROM db_name.table_name'
))