Note: It's possible that you need to authorize ClickHouse Cloud to access to your MySQL instance. The full list of ClickHouse Cloud egress IP addresses is available here.
Use the the MySQL table function
You can use the MySQL table function to query remote MySQL tables.
SELECT * FROM mysql('<mysql_host>:<port>', '<database>', '<table>', '<user>', '<password>');
Create a MySQL table without providing a schema
You can also create a table using PostgreSQL table engine in your ClickHouse Cloud service without specifying a schema using the CREATE TABLE AS
syntax. When ClickHouse creates the table locally, types in MySQL will be mapped to equivalent ClickHouse types.
CREATE TABLE mycountries AS mysql('<mysql_host>:<port>', '<database>', '<table>', '<user>', '<password>');
Note: You can use the setting
external_table_functions_use_nulls = 0
to ensure Null values are represented as their default values (instead of Null). If set to 1 (the default), ClickHouse will create Nullable variants of each column.
Create a MySQL table with a custom schema
You can also decide to create a table with the MySQL table engine in your ClickHouse service by specifying a custom schema.
CREATE TABLE default.mysql_table
(
`float_nullable` Nullable(Float32),
`str` String,
`int_id` Int32
)
ENGINE = mysql('<mysql_host>:<port>', '<database>', '<table>', '<user>', '<password>')