Schedule a MySQL transfer

The BigQuery Data Transfer Service MySQL connector lets you ingest data from your MySQL instance into BigQuery. It supports MySQL instances that are hosted in your on-premises environment, in Cloud SQL, and in other public cloud providers such as Amazon Web Services (AWS) and Microsoft Azure. The BigQuery Data Transfer Service MySQL connector also lets you create on-demand and recurring data transfer jobs for transferring data from a MySQL database to BigQuery.

Before you begin

Required roles

If you intend to set up transfer run notifications for Pub/Sub, ensure that you have the pubsub.topics.setIamPolicy Identity and Access Management (IAM) permission. Pub/Sub permissions are not required if you only set up email notifications. For more information, see BigQuery Data Transfer Service run notifications.

To get the permissions that you need to create a MySQL data transfer, ask your administrator to grant you the BigQuery Admin (roles/bigquery.admin) IAM role on your project. For more information about granting roles, see Manage access to projects, folders, and organizations.

This predefined role contains the permissions required to create a MySQL data transfer. To see the exact permissions that are required, expand the Required permissions section:

Required permissions

The following permissions are required to create a MySQL data transfer:

  • bigquery.transfers.update
  • bigquery.datasets.get

You might also be able to get these permissions with custom roles or other predefined roles.

Network connections

If a public IP address is not available for the MySQL database connection, you must set up a network attachment.

For detailed instructions on the required network setup, refer to the following documents:

Limitations

MySQL data transfers are subject to following limitations:

  • The maximum number of simultaneous connections to a MySQL database is determined by the MySQL configuration parameter max_connections. By default, this is set to 151 connections, but it can be configured to a higher limit as needed. As a result, the number of simultaneous transfer runs to a single MySQL database is limited to that maximum amount. This limitation also means that the number of concurrent transfer jobs should be limited to a value less than the maximum number of concurrent connections supported by the MySQL database.
  • In MySQL, some data types get mapped to the string type in BigQuery to avoid any data loss. For example, numeric types defined in MySQL that don't have a defined precision and scale are mapped to the string type in BigQuery.

Set up a MySQL data transfer

Select one of the following options:

Console

  1. Go to the Data transfers page.

    Go to Data transfers

  2. Click Create transfer.

  3. In the Source type section, for Source, select MySQL.

  4. In the Transfer config name section, for Display name, enter a name for the transfer. The transfer name can be any value that lets you identify the transfer if you need to modify it later.

  5. In the Schedule options section, do the following:

    • Select a repeat frequency. If you select the Hours, Days (default), Weeks, or Months option, you must also specify a frequency. You can also select the Custom option to create a more specific repeat frequency. If you select the On-demand option, this data transfer only runs when you manually trigger the transfer.
    • If applicable, select either the Start now or Start at a set time option and provide a start date and run time.
  6. In the Destination settings section, for Dataset, select the dataset that you created to store your data, or click Create new dataset and create one to use as the destination dataset.

  7. In the Data source details section, do the following:

    • For Network attachment, select an existing network attachment or click Create Network Attachment. For more information, see the Network connections section of this document.
    • For Host, enter the hostname or IP address of the MySQL database server.
    • For Port number, enter the port number for the MySQL database server.
    • For Database name, enter the name of the MySQL database.
    • For Username, enter the username of the MySQL user initiating the MySQL database connection.
    • For Password, enter the password of the MySQL user initiating the MySQL database connection.
    • For Encryption mode, select Full from the menu to enable full SSL validation when connecting to the MySQL database, or select Disable for no SSL validation.
    • For MySQL objects to transfer, do one of the following:

      • Click Browse to select the MySQL tables that are required for the transfer, and then click Select.
      • Manually enter the names of the tables in the MySQL objects to transfer.

    Data source details on the Create transfer page

  8. Optional: In the Service account menu, specify a custom service account to authorize the transfer. Ensure that the service account that is used has all the necessary roles and permissions. For more information, see Transfer owner as a service account.

  9. Optional: In the Notification options section, do the following:

    • To enable email notifications, click the Email notifications toggle to the on position. When you enable this option, the transfer administrator receives an email notification when a transfer run fails.
    • To configure Pub/Sub run notifications for your transfer, click the Pub/Sub notifications toggle to the on position. You can select your topic name or click Create a topic to create one.
  10. Click Save.

bq

Enter the bq mk command and supply the transfer creation flag --transfer_config:

bq mk \
    --transfer_config \
    --project_id=PROJECT_ID \
    --data_source=DATA_SOURCE \
    --display_name=DISPLAY_NAME \
    --target_dataset=DATASET \
    --params='PARAMETERS'

Replace the following:

  • PROJECT_ID (optional): your Google Cloud project ID. If the --project_id flag isn't supplied to specify a particular project, the default project is used.
  • DATA_SOURCE: the data source, which is mysql.
  • DISPLAY_NAME: the display name for the data transfer configuration. The transfer name can be any value that lets you identify the transfer if you need to modify it later.
  • DATASET: the target dataset for the data transfer configuration.
  • PARAMETERS: the parameters for the created transfer configuration in JSON format. For example: --params='{"param":"param_value"}'. The following are the parameters for a MySQL transfer:

    • networkAttachment (optional): the name of the network attachment to connect to the MySQL database.
    • connector.database: the name of the MySQL database.
    • connector.endpoint.host: the hostname or IP address of the database.
    • connector.endpoint.port: the port number of the database.
    • connector.authentication.username: the username of the database user.
    • connector.authentication.password: the password of the database user. connector.connectionType
    • connector.connectionType (optional): the connection type to determine the connection URL. This can be SERVICE, SID, or TNS. When not provided, this defaults to SERVICE.
    • connector.encryptionMode: the encryption mode. This can be FULL for full SSL validation when connecting to the MySQL database, or DISABLE for no SSL validation.
    • assets: a list of the names of the MySQL tables to be transferred from the MySQL database as part of the transfer.

For example, the following command creates a MySQL transfer called My Transfer:

bq mk \
    --transfer_config \
    --target_dataset=mydataset \
    --data_source=mysql \
    --display_name='My Transfer' \
    --params='{"assets":["DB1/DEPARTMENT","DB1/EMPLOYEES"], \
        "connector.authentication.username": "User1", \
        "connector.authentication.password":"ABC12345", \
        "connector.encryptionMode":"FULL", \
        "connector.database":"DB1", \
        "connector.endpoint.host":"54.74.220.23", \
        "connector.endpoint.port":"3306"}'

API

Use the projects.locations.transferConfigs.create method and supply an instance of the TransferConfig resource.

Data type mapping

The following table maps MySQL data types to the corresponding BigQuery data types.

MySQL data type BigQuery data type
BIT BOOLEAN
TINYINT INTEGER
BOOL, BOOLEAN BOOLEAN
SMALLINT INTEGER
MEDIUMINT INTEGER
INT, INTEGER INTEGER
BIGINT BIGNUMERIC
FLOAT FLOAT
DOUBLE FLOAT
DECIMAL BIGNUMERIC
DATE DATE
DATETIME TIMESTAMP
TIMESTAMP TIMESTAMP
TIME TIME
YEAR DATE
CHAR STRING
VARCHAR STRING
BINARY BYTES
VARBINARY BYTES
TINYBLOB BYTES
TINYTEXT STRING
BLOB BYTES
TEXT STRING
MEDIUMBLOB BYTES
MEDIUMTEXT STRING
LONGBLOB BYTES
LONGTEXT STRING
ENUM STRING
SET STRING

Troubleshoot

If you are having issues setting up your data transfer, see MySQL transfer issues.

What's next