Before you synchronize data from MySQL to DataHub in real time, you can refer to the operations described in this topic to configure data sources. The configurations of data sources include network environments, whitelists, and permissions. You must configure a source MySQL data source and a destination DataHub data source.

Prerequisites

Before you configure data sources, make sure that the following operations are performed:
  • Prepare data sources: A MySQL database and a DataHub project are prepared.
  • Plan and prepare resources: An exclusive resource group for data integration is purchased and configured. For more information, see Plan and configure resources.
  • Evaluate and plan the network environment: Before you perform data integration, connect data sources to exclusive resource groups for Data Integration based on your business requirements. After data sources and exclusive resource groups for Data Integration are connected, you can refer to the operations in this topic to configure access settings such as vSwitches and whitelists.
    • If data sources and exclusive resource groups for Data Integration reside in the same region and virtual private cloud (VPC), they are automatically connected.
    • If data sources and exclusive resource groups for Data Integration reside in different network environments, you must connect data sources and resource groups by using methods such as a VPN gateway.

Background information

Before you synchronize data from the source to the destination, make sure that the data sources and the exclusive resource group for Data Integration are connected. In addition, you must create an account and authorize the account to access the data sources.
  • Configure whitelists for data sources
    If the data sources and exclusive resource group for data integration reside in the same VPC, you must add the CIDR block of the exclusive resource group for data integration to the whitelists of the data sources. This ensures that the exclusive resource group for data integration can be used to access the data sources.VPC connection
  • Create an account and grant permissions the account

    You must create an account that can be used to access the data sources, read data from the source, and write data to the destination during the data synchronization process.

  • Enable the binary logging feature

    If the source data source is a MySQL database, you must enable the binary logging feature. Binary logs record changes to all table schemas and modifications on table data. You can execute statements such as CREATE and ALTER to perform operations on table schemas. You can execute statements such as INSERT, UPDATE, and DELETE to perform operations on table data. You can use binary logs to view the change history of the database, back up incremental data and restore data in the database, and replicate data from the primary database to secondary databases.

    Formats of binary logs:
    • Statement: SQL statement-based replication. Binary logs in this format record the SQL statements that are executed to modify data entries.
    • Row: row-based replication. Binary logs in this format record only modification details about data entries in rows.
    • Mixed: replication in mixed mode. This mode combines the statement and row formats. In most cases, binary logs in the statement format are used to record the SQL statements that are executed to modify data entries, such as functions. If data replication from the primary database to secondary databases cannot be implemented by using binary logs in this format, switch to the row format. MySQL determines which format to use based on each SQL statement that is executed.

Procedure

  1. Configure a whitelist for a MySQL database.
    Add the CIDR block of the VPC where the exclusive resource group resides to the whitelist of the MySQL database.
    1. View and record the EIP and CIDR block of the exclusive resource group.
    2. Add the EIP and CIDR block of the exclusive resource group to the whitelist of the MySQL database.
  2. Create an account and grant the required permissions to the account.
    You must create an account to log on to the MySQL database. You must grant the SELECT, REPLICATION SLAVE, and REPLICATION CLIENT permissions to the account.
    1. Create an account.
    2. Grant permissions to the account.
      You can run the following command to grant permissions to the account. Alternatively, you can grant the SUPER permission to the account. Replace Account for data synchronization with the created account when you execute the specific statement.
      -- CREATE USER 'Account for data synchronization'@'%' IDENTIFIED BY 'Password'; // Create an account that is used to synchronize data and set a password so that you can use the account and password to access the database from a host. % indicates a host.
      GRANT SELECT, REPLICATION SLAVE, REPLICATION CLIENT ON *. * TO 'Account for data synchronization'@'%'; // Grant the SELECT, REPLICATION SLAVE, and REPLICATION CLIENT permissions to the account.
      *.* indicates that the synchronization account is granted the preceding permissions on all tables in all databases. You can also grant the preceding permissions on specified tables in the destination database to the synchronization account. For example, to grant the account the preceding permissions on the user table in the test database, execute the following statement: GRANT SELECT, REPLICATION SLAVE, REPLICATION CLIENT ON test.user TO 'Account for data synchronization'@'%';.
    3. Enable the binary logging feature for the MySQL database.
      Perform the following steps to check whether the binary logging feature is enabled and to query the format of binary logs:
      • Execute the following statement to check whether the binary logging feature is enabled:
        show variables like "log_bin";

        If ON is displayed in the returned result, the binary logging feature is enabled.

      • If you use a secondary database to synchronize data, execute the following statement to check whether the binary logging feature is enabled:
        show variables like "log_slave_updates";

        If ON is displayed in the returned result, the binary logging feature is enabled for the secondary database.

      If the returned result is different from the preceding result, follow the instructions described in the MySQL documentation to enable the binary logging feature.
      Execute the following statement to view the format of binary logs:
      show variables like "binlog_format";
      Returned result:
      • ROW: The format of binary logs is row.
      • STATEMENT: The format of binary logs is statement.
      • MIXED: The format of binary logs is mixed.

What to do next

After data sources are configured, the source data source, destination data source, and exclusive resource group for Data Integration are connected. Then, the exclusive resource group for Data Integration can be used to access the data sources. You can add the source data source and destination data source to DataWorks, and associate them with a data synchronization solution when you create the solution.

For more information about how to add a data source, see Add a data source.