MySQL¶
The MySQL engine allows you to perform SELECT
queries on data that is stored on a remote MySQL server.
Call format:
MySQL('host:port', 'database', 'table', 'user', 'password'[, replace_query, 'on_duplicate_clause']);
Call parameters
host:port
— Address of the MySQL server.database
— Database name on the MySQL server.table
— Name of the table.user
— The MySQL User.password
— User password.replace_query
— Flag that sets query substitutionINSERT INTO
toREPLACE INTO
. Ifreplace_query=1
, the query is replaced.-
on_duplicate_clause
— Adds theON DUPLICATE KEY on_duplicate_clause
expression to theINSERT
query.Example:
INSERT INTO t (c1,c2) VALUES ('a', 2) ON DUPLICATE KEY UPDATE c2 = c2 + 1
, whereon_duplicate_clause
isUPDATE c2 = c2 + 1
. See MySQL documentation to find whichon_duplicate_clause
you can use withON DUPLICATE KEY
clause.To specify
on_duplicate_clause
you need to pass0
to thereplace_query
parameter. If you simultaneously passreplace_query = 1
andon_duplicate_clause
, ClickHouse generates an exception.
At this time, simple WHERE
clauses such as =, !=, >, >=, <, <=
are executed on the MySQL server.
The rest of the conditions and the LIMIT
sampling constraint are executed in ClickHouse only after the query to MySQL finishes.
The MySQL
engine does not support the Nullable data type, so when reading data from MySQL tables, NULL
is converted to default values for the specified column type (usually 0 or an empty string).