Yandex Cloud
Search
Contact UsGet started
  • Pricing
  • Customer Stories
  • Documentation
  • Blog
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • AI for business
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Start testing with double trial credits
    • Cloud credits to scale your IT product
    • Gateway to Russia
    • Cloud for Startups
    • Center for Technologies and Society
    • Yandex Cloud Partner program
  • Pricing
  • Customer Stories
  • Documentation
  • Blog
© 2025 Direct Cursus Technology L.L.C.
Yandex Data Transfer
  • Available transfers
  • Getting started
    • All tutorials
      • Greenplum® to ClickHouse®
      • MySQL® in ClickHouse®
      • Yandex Metrica to ClickHouse®
      • PostgreSQL in ClickHouse®
      • Greenplum® to PostgreSQL
      • Object Storage in MySQL®
      • Object Storage to PostgreSQL
      • Object Storage to Greenplum®
      • Yandex Direct to ClickHouse®
      • Object Storage in ClickHouse®
      • Object Storage to YDB
      • YDB to ClickHouse®
      • OpenSearch in ClickHouse®
  • Troubleshooting
  • Access management
  • Pricing policy
  • Terraform reference
  • Monitoring metrics
  • Audit Trails events
  • Public materials

In this article:

  • Required paid resources
  • Getting started
  • Prepare the source cluster
  • Set up and activate the transfer
  • Test the transfer
  • Query data in ClickHouse®
  • Delete the resources you created
  1. Tutorials
  2. Uploading data to data marts
  3. MySQL® in ClickHouse®

Loading data from MySQL® to a ClickHouse® data mart

Written by
Yandex Cloud
Updated at November 26, 2025
  • Required paid resources
  • Getting started
  • Prepare the source cluster
  • Set up and activate the transfer
  • Test the transfer
  • Query data in ClickHouse®
  • Delete the resources you created

Data Transfer enables you to migrate your database from a MySQL® source cluster to ClickHouse®.

To transfer data:

  1. Prepare the source cluster.
  2. Set up and activate the transfer.
  3. Test your transfer.
  4. Query data in ClickHouse®.

If you no longer need the resources you created, delete them.

Required paid resourcesRequired paid resources

  • Managed Service for MySQL® cluster: computing resources allocated to hosts, size of storage and backups (see Managed Service for MySQL® pricing).
  • Managed Service for ClickHouse® cluster: use of computing resources allocated to hosts, size of storage and backups (see Managed Service for ClickHouse® pricing).
  • Public IP addresses if public access is enabled for cluster hosts (see Virtual Private Cloud pricing).
  • Each transfer: use of computing resources and number of transferred data rows (see Data Transfer pricing).

Getting startedGetting started

Set up the infrastructure:

Manually
Terraform
  1. Create a Managed Service for MySQL® source cluster with your preferred configuration. Enable public access to the cluster during creation so you can connect to it from your local machine. Connections from within the Yandex Cloud network are enabled by default.

  2. Create a Managed Service for ClickHouse® target cluster with the following settings:

    • Number of ClickHouse® hosts: Minimum of 2 to enable replication within the cluster.
    • Database name: Must be identical to the database name in the source cluster.
    • Enable public access to the cluster during creation so you can connect to it from your local machine. Connections from within the Yandex Cloud network are enabled by default.
  3. If using security groups, configure them to allow internet access to your clusters:

    • Managed Service for MySQL®.
    • Managed Service for ClickHouse®.
  1. If you do not have Terraform yet, install it.

  2. Get the authentication credentials. You can add them to environment variables or specify them later in the provider configuration file.

  3. Configure and initialize a provider. There is no need to create a provider configuration file manually, you can download it.

  4. Place the configuration file in a separate working directory and specify the parameter values. If you did not add the authentication credentials to environment variables, specify them in the configuration file.

  5. Download the data-transfer-mmy-mch.tf configuration file to your current working directory.

    This file describes:

    • Network.
    • Subnets.
    • Security group and the rule permitting access to the Managed Service for MySQL® cluster.
    • Managed Service for MySQL® source cluster.
    • Managed Service for ClickHouse® target cluster.
    • Source endpoint.
    • Target endpoint.
    • Transfer.
  6. In the data-transfer-mmy-mch.tf file, specify the following:

    • Source endpoint parameters inherited from the Managed Service for MySQL® source cluster :

      • source_mysql_version: MySQL® version.
      • source_db_name: MySQL® database name.
      • source_user and source_password: Database owner username and password.
    • Target endpoint parameters inherited from the Managed Service for ClickHouse® target cluster:

      • target_db_name: ClickHouse® database name.
      • target_user and target_password: Database owner username and password.
  7. Make sure the Terraform configuration files are correct using this command:

    terraform validate
    

    Terraform will show any errors found in your configuration files.

  8. Create the required infrastructure:

    1. Run this command to view the planned changes:

      terraform plan
      

      If you described the configuration correctly, the terminal will display a list of the resources to update and their parameters. This is a verification step that does not apply changes to your resources.

    2. If everything looks correct, apply the changes:

      1. Run this command:

        terraform apply
        
      2. Confirm updating the resources.

      3. Wait for the operation to complete.

    All the required resources will be created in the specified folder. You can check resource availability and their settings in the management console.

Prepare the source clusterPrepare the source cluster

  1. If you created the infrastructure manually, you must now prepare your source cluster.

  2. Connect to the Managed Service for MySQL® source cluster.

  3. Add test data to the database.

    1. Create a table named x_tab:
    CREATE TABLE x_tab
    (
        id INT,
        name TEXT,
        PRIMARY KEY (id)
    );
    
    1. Populate the table with data:
    INSERT INTO x_tab (id, name) VALUES
        (40, 'User1'),
        (41, 'User2'),
        (42, 'User3'),
        (43, 'User4'),
        (44, 'User5');
    

Set up and activate the transferSet up and activate the transfer

Manually
Terraform
  1. Create a source endpoint:

    • Database type: MySQL®

    • Endpoint parameters → Connection settings: Managed Service for MySQL cluster

      Select your source cluster from the list and specify its connection settings.

  2. Create a target endpoint:

    • Database type: ClickHouse

    • Endpoint parameters → Connection settings: Managed cluster

      Select your target cluster from the list and specify its connection settings.

  3. Create a transfer of the Snapshot and replication type that will use the new endpoints.

  4. Activate the transfer.

  1. In the data-transfer-mmy-mch.tf file, set the transfer_enabled variable to 1.

  2. Make sure the Terraform configuration files are correct using this command:

    terraform validate
    

    Terraform will show any errors found in your configuration files.

  3. Create the required infrastructure:

    1. Run this command to view the planned changes:

      terraform plan
      

      If you described the configuration correctly, the terminal will display a list of the resources to update and their parameters. This is a verification step that does not apply changes to your resources.

    2. If everything looks correct, apply the changes:

      1. Run this command:

        terraform apply
        
      2. Confirm updating the resources.

      3. Wait for the operation to complete.

    The transfer will activate automatically upon creation.

Test the transferTest the transfer

  1. Wait for the transfer status to change to Replicating.

  2. Verify that the data has been transferred from the source Managed Service for MySQL® cluster to the Managed Service for ClickHouse® database:

    1. Connect to the cluster via clickhouse-client.

    2. Run this query:

      SELECT * FROM <ClickHouse®_database_name>.x_tab
      

      Result:

      ┌─id─┬─name──┬─__data_transfer_commit_time─┬─__data_transfer_delete_time─┐
      │ 40 │ User1 │         1661952756538347180 │                           0 │
      │ 41 │ User2 │         1661952756538347180 │                           0 │
      │ 42 │ User3 │         1661952756538347180 │                           0 │
      │ 43 │ User4 │         1661952756538347180 │                           0 │
      │ 44 │ User5 │         1661952756538347180 │                           0 │
      └────┴───────┴─────────────────────────────┴─────────────────────────────┘
      

      The table also contains the following timestamp columns: __data_transfer_commit_time and __data_transfer_delete_time.

  3. In the source MySQL® table x_tab, delete the row with id = 41 and update the row with id = 42:

    1. Connect to the Managed Service for MySQL® source cluster.

    2. Run the following queries:

      DELETE FROM x_tab WHERE id = 41;
      UPDATE x_tab SET name = 'Key3' WHERE id = 42;
      
  4. Make sure the changes have been applied to the x_tab table on the ClickHouse® target:

    SELECT * FROM <ClickHouse®_database_name>.x_tab WHERE id in (41,42);
    

    Result:

    ┌─id─┬─name──┬─__data_transfer_commit_time─┬─__data_transfer_delete_time─┐
    │ 41 │ User2 │         1661952756538347180 │                           0 │
    │ 42 │ User3 │         1661952756538347180 │                           0 │
    └────┴───────┴─────────────────────────────┴─────────────────────────────┘
    ┌─id─┬─name─┬─__data_transfer_commit_time─┬─__data_transfer_delete_time─┐
    │ 41 │ ᴺᵁᴸᴸ │         1661953256000000000 │         1661953256000000000 │
    └────┴──────┴─────────────────────────────┴─────────────────────────────┘
    ┌─id─┬─name─┬─__data_transfer_commit_time─┬─__data_transfer_delete_time─┐
    │ 42 │ Key3 │         1661953280000000000 │                           0 │
    └────┴──────┴─────────────────────────────┴─────────────────────────────┘
    

Query data in ClickHouse®Query data in ClickHouse®

For table recovery, ClickHouse® targets with replication use the ReplicatedReplacingMergeTree and ReplacingMergeTree engines. The following columns are automatically added to each table:

  • __data_transfer_commit_time: Time in TIMESTAMP format when this row was last updated.

  • __data_transfer_delete_time: Time in TIMESTAMP format when this row was deleted from the source table. A value of 0 indicates that the row is still active.

    The __data_transfer_commit_time column is essential for the ReplicatedReplacedMergeTree engine. It tracks changes by inserting a new version of a row upon any update or deletion, timestamped with the operation's commit time. Consequently, a query by a primary key may return multiple row versions with different __data_transfer_commit_time values.

The source data can be added or deleted while the transfer is in the Replicating status. To ensure an SQL query by a primary key returns a single record, always filter on __data_transfer_delete_time when querying tables transferred to ClickHouse®. For example, to query the x_tab table, use the following syntax:

SELECT * FROM <ClickHouse®_database_name>.x_tab FINAL
WHERE __data_transfer_delete_time = 0;

To simplify the SELECT queries, create a view filtering rows by __data_transfer_delete_time. Use this view for all your queries. For example, to query the x_tab table, use the following syntax:

CREATE VIEW x_tab_view AS SELECT * FROM <ClickHouse®_database_name>.x_tab FINAL
WHERE __data_transfer_delete_time == 0;

Delete the resources you createdDelete the resources you created

Note

Before deleting the created resources, deactivate the transfer.

Some resources are not free of charge. To avoid paying for them, delete the resources you no longer need:

Manually
Terraform
  1. Delete the transfer.
  2. Delete the source and target endpoints.
  3. Delete the Managed Service for MySQL® cluster.
  4. Delete the Managed Service for ClickHouse® cluster.
  1. In the terminal window, go to the directory containing the infrastructure plan.

    Warning

    Make sure the directory has no Terraform manifests with the resources you want to keep. Terraform deletes all resources that were created using the manifests in the current directory.

  2. Delete resources:

    1. Run this command:

      terraform destroy
      
    2. Confirm deleting the resources and wait for the operation to complete.

    All the resources described in the Terraform manifests will be deleted.

ClickHouse® is a registered trademark of ClickHouse, Inc.

Was the article helpful?

Previous
Greenplum® to ClickHouse®
Next
Yandex Metrica to ClickHouse®
© 2025 Direct Cursus Technology L.L.C.