You need to enable JavaScript to run this app.
ByteHouse Cloud Data Warehouse Version

ByteHouse Cloud Data Warehouse Version

Copy page
Download PDF
Appearance
MySQL external table
Copy page
Download PDF
MySQL external table

This article provides an Intro to the syntax and usage for creating MySQL External Databases and External tables.

Background information

ByteHouse supports MySQL external tables, using the MySQL engine to Run Data Search on data stored on remote MySQL servers.

MySQL data mapping method

For MySQL tables, ByteHouse currently supports create MySQL external table, create MySQL External Database, create MySQL External Catalog—three methods to achieve data mapping between ByteHouse and MySQL.

Data mapping method

Data mapping description

Create MySQL external table

At the table level, establish a mapping from ByteHouse table to MySQL table. Schema changes in the source table will not be directly synchronized. If there are changes, you need to delete the external table in ByteHouse and create a new external table.

Create MySQL external database

At the database level, establish a mapping from ByteHouse Database to MySQL Database. After establishing the database mapping, there is no need to manually create table mappings; table mappings under the database can be automatically synchronized. It can detect additions and deletions of MySQL tables, and schema changes in the source table can be directly synchronized to ByteHouse.

Create MySQL external catalog

At the catalog level, establish a mapping from ByteHouse Catalog to MySQL Catalog. After establishing the catalog mapping, there is no need to manually create database and table mappings; database and table mappings under the catalog can be automatically synchronized. It can detect additions and deletions of Paimon databases and tables, and schema changes in the source table can be directly synchronized to ByteHouse. For details on creating a MySQL external catalog, please refer to MySQL Catalog.

Fee description

The function of External tables is designed to provide processing capabilities for data beyond ByteHouse internal tables. With a simple DDL statement, you can create an External table in ByteHouse and establish an association between the ByteHouse table and the External data source.

  • External tables in ByteHouse only incur calculation fees, following ByteHouse's calculation resource billing rules.
  • When using the External table function, data in the External table will not be copied to ByteHouse or incur storage fees. For storage fees, please follow the billing rules of the external data source's storage side.
  • When accessing an external data source using ByteHouse external tables, the external data source may incur calculation, access, data transmission, and other fees. The specific fees are subject to the external data source's billing method. Please refer to the relevant product's description. Prerequisites

Before performing create, search, update, or delete actions for MySQL external tables, ensure you have acquired the corresponding read and write privileges for the database and table.

Prerequisites

Before performing search or management actions for MySQL external tables, ensure you have acquired the corresponding read and write privileges for the table.

Limitations
  • The current network requirements for accessing MySQL external tables are as follows:
    • Private network access requires the Private Link method. To use this method, contact the ByteHouse team to enable it.
    • Public network access requires configuration of ByteHouse's public IP. For settings details, refer to Network information settings.
  • If your network environment has access limitations, add the ByteHouse service IP address to the allowlist. For details, refer to Set IP allowlist.

Create MySQL external table
CREATE TABLE [IF NOT EXISTS] [db.]table_name (
    name1 [type1] [DEFAULT|MATERIALIZED|ALIAS expr1] [TTL expr1],
    name2 [type2] [DEFAULT|MATERIALIZED|ALIAS expr2] [TTL expr2],
    ...
) ENGINE = MySQL('host:port', 'database', 'table', 'user', 'password'[, replace_query, 'on_duplicate_clause']);

Parameters

Configuration description

Table description

  • [db.]table_name: Fill in the database name and table name of the MySQL external table. If you run the USE DATABASE db command before creating the MySQL external table, db here can be omitted. [] indicates that this field can be omitted.
  • name1 [type1]: The column name and data type of the MySQL table.
    • The column name must be consistent with the MySQL source table.
    • ByteHouse is compatible with commonly used functions and syntax of MySQL 5.7 and MySQL 8.0. For more information about data type compatibility, please refer to Environment Preparation.
  • [DEFAULT
    • DEFAULT: Optional, sets a default value expression for the column.
    • MATERIALIZED: Optional, sets a materialized view expression for the column.
    • ALIAS expr1: Optional, sets an alias expression for the column.
  • [TTL expr1]: Optional, set a lifecycle expression for the column.

Engine parameters (Engine)

  • host:port: fill in the MySQL server address.

    warning

    This host:port must support public network access.

  • database: fill in the MySQL database name.
  • table: fill in the MySQL table name.
  • user: fill in the MySQL username.
  • password: fill in the MySQL password.
  • replace_query: Optional, value can be 0 or 1, used to control conflict processing during writing:
    • Value 1: Enable REPLACE mode. If a primary key or unique key conflict occurs during writing, directly replace the existing data in the MySQL source table.
    • Value 0 (default): Disable REPLACE mode. In case of conflict, return an error.
  • on_duplicate_clause: Optional, customize the conflict processing clause (only effective when replace_query=0), must comply with the MySQL ON DUPLICATE KEY UPDATE syntax.
    • Example: 'ON DUPLICATE KEY UPDATE name=VALUES(name), age=VALUES(age)';
    • You must ensure that the MySQL source table has a primary key or unique key; otherwise, this clause is invalid.

Example
When using, replace the examples in the command with the actual connection address, database, table, username, and password.

DROP TABLE IF EXISTS demo_db.mysql_table; 

-- create MySQL external table. You need to ensure that the DDL of the sync table and ByteHouse are consistent
CREATE TABLE demo_db.mysql_table(
    id Int32,
    name String
) ENGINE = MySQL('127.x.x.1:3306', 'test_db', 'test_tb', 'demo_user', 'password');

-- View the create table statement
SHOW CREATE TABLE demo_db.mysql_table;

Create MySQL external database

By creating a ByteHouse external database, establish a mapping from ByteHouse Database to MySQL Database at the database level. After establishing the database mapping, there is no need to manually create table mappings; table mappings under the database can be automatically synchronized.

CREATE DATABASE [IF NOT EXISTS] database_name
ENGINE = MySQL('host:port', 'database', 'user', 'password');

Param

Configuration description

Database description

Customize external database name.

Engine parameters (Engine)

  • host:port: fill in the MySQL server address.

    warning

    This host:port must support public network access. To access via private network, contact the ByteHouse team to enable Private Link.

  • database: fill in the MySQL database name.
  • user: fill in the MySQL username.
  • password: fill in the MySQL password.

Example
When using, please replace the placeholders in the command with the actual connection address, database, username, and password.

-- create MySQL external database
CREATE DATABASE mysql_db
ENGINE = MySQL('127.x.x.1:3306', 'test_db', 'demo_user', 'password');

-- Search the create database statement
SHOW CREATE DATABASE mysql_db;

Query external table

The query operation for external tables is consistent with that for normal tables.

SELECT * FROM demo_db.mysql_table LIMIT 10;

Delete external database table

The delete operation for external database tables is consistent with that for normal tables.

  • Delete external database

    warning

    After you delete the external database, all external tables under the external database will also be deleted. Please proceed with caution.

    DROP DATABASE mysql_db
    
  • Delete external table

    DROP TABLE demo_db.mysql_table
    
Last updated: 2026.03.31 16:21:57