Google Cloud SQL offers MySQL as a fully-managed web service. You can use Google Cloud SQL to host your MySQL database in Google Cloud Platform, and let Google Cloud handle administrative tasks such a replication, patch management, and database management for it.
You can ingest data from your Google Cloud MySQL database using Hevo Pipelines and replicate it to a Destination of your choice.
Prerequisites
Perform the following steps to configure your Google Cloud MySQL Source:
Create a Read Replica (Optional)
If you are using an existing read-replica or connecting Hevo to your master database, skip to Set up MySQL Binary Logs for Replication section.
To create a read-replica:
-
Log in to the Google Cloud Console.
-
Access the Google Cloud SQL Instances page and click your Instance ID.
-
In the left navigation pane, click Replicas, and then click + CREATE READ REPLICA.
-
Specify the instance information relevant to your requirements, and then click CREATE REPLICA.
Set up MySQL Binary Logs for Replication
A binary log is a collection of log files that records information about data modifications and data object modifications made on a MySQL server instance. Typically binary logs are used for data replication and data recovery.
Hevo supports data ingestion for replication from servers via binary logs (BinLog). For this, binary logging must be enabled on your Google Cloud MySQL server.
To do this:
1. Check if BinLog replication is already enabled
-
Access your Google Cloud MySQL instance.
-
In the left navigation pane, under Databases, select Backups.
-
Under Settings, check the status of Automated backups.
-
If the status is Disabled, provided below to enable BinLog replication. If the status is Enabled, ensure that the BinLog retention period is set to at least 3 days by following the steps provided below.
-
In the left navigation pane, click Overview, and then click EDIT.
-
Scroll down to the Data Protection panel and select the Automated daily backups and Enable point-in-time recovery check boxes.
-
In the Flags panel, click ADD A DATABASE FLAG.
-
Click the Choose a flag field, and from the drop-down list, search and select the binlog_expire_logs_seconds
flag.
-
Set the Value greater than or equal to 259200 (three days), and then click DONE.
Note: Ensure that the Value of binlog_row_value_options
flag is not set to PARTIAL_JSON.
-
Click SAVE.
This confirms that binary logging is now enabled for your Google Cloud MySQL instance.
The replication reference guide on MySQL’s documentation portal provides a complete reference of the options available for replication and binary logging.
3. Enabling GTIDs (Recommended)
Enabling GTID is recommended because it makes replication simpler and helps ensure that the primary and replica servers are in sync with each other.
-
Access your MySQL database server.
-
Run the following commands:
SET GLOBAL enforce_gtid_consistency = ON;
SET GLOBAL gtid_mode = OFF_PERMISSIVE;
SET GLOBAL gtid_mode = ON_PERMISSIVE;
SET GLOBAL gtid_mode = ON;
-
Confirm the changes:
show global variables like '%GTID%';
Allowlist Hevo IP addresses for your region
You need to allowlist the Hevo IP address for your region to enable Hevo to connect to your Google Cloud MySQL database:
-
Access the Google Cloud MySQL Instances page and click the Instance ID that you want to use.
-
In the left navigation pane, click Connections.
-
On the Connections page, do the following:
-
Go to the NETWORKING tab.
-
Click the Public IP check box.
-
Click the ADD A NETWORK and specify the following:
-
Name: A name for this connection. For example, all or Hevo IP address.
-
Network: The IP address of the site to grant access to. Specify 0.0.0.0/0 to authorize all sites or 10.2.7.152 to specifically whitelist Hevo’s IP address. Check the Hevo IP address for your region.
-
Click DONE.
This adds the IP address to the list of Authorized networks.
-
(Optional) Click Add A NETWORK to add another IP address.
-
Click SAVE.
Create a Database User and Grant Privileges
MySQL allows you to connect to Hevo after you configure your Google Cloud MySQL instance as an existing user or as a new user. To do this, select one of the following options:
Option 1. Configuring the user account using Google Cloud console
-
Click the primary Google Cloud MySQL instance.
-
In the left navigation pane, under PRIMARY INSTANCE, select Users, and then click + ADD USER ACCOUNT.
-
In the Add a user account to instance window, select one of the following methods to authenticate your user to access the instance:
-
Authentication method:
-
Built-in authentication: This uses a username and password to authenticate local database users
- Host name: The host name determines which client hosts can connect to your instance with this user account. Default value: Allow any host (%).
-
Cloud IAM: This uses an IAM principal that provides access to the required resources in your Google Cloud MySQL instance.
-
Click ADD.
You will specify this username and password while creating your Hevo Pipeline.
Option 2. Configuring the user account using MySQL client
The database user specified in the Hevo Pipeline must have the following global privileges:
-
SELECT
- Select data from tables in your database which you want to replicate.
-
RELOAD
- Access to clear or reload internal caches, flush tables, or acquire locks.
-
SHOW DATABASES
- View list of database names in the server.
-
REPLICATION CLIENT
- Access to the MySQL server BinLog for replication.
-
REPLICATION SLAVE
- Access replication status and log details.
Note: The SELECT
, RELOAD
, and SHOW DATABASES
privileges are only required during the historical load.
-
Connect to your Google Cloud MySQL database as a root user with an SQL client tool, such as MySQL workbench.
-
Create a database user:
CREATE USER '<username>'@'%' IDENTIFIED BY '<password>';
Note: We recommend creating a database user for connecting to your Google Cloud MySQL Source in Hevo. However, if you already have one, skip to step 3 below.
-
Grant the required privileges to the user:
GRANT SELECT, RELOAD, SHOW DATABASES, REPLICATION CLIENT, REPLICATION SLAVE ON *.* TO '<username>'@'%';
Note:
-
Replace the placeholder values in the commands above with your own. For example, <username> with hevo.
-
The REPLICATION SLAVE
privilege is required only if you connect to a read replica. When it is granted to the authenticating user, the replica logs any updates received from the main database, maintaining a record of those changes in its log.
-
Finalize the user’s permissions:
Retrieve the Configuration Details (Optional)
1. Retrieve the database hostname and port number
Note: Following is an example of Google Cloud MySQL hostname and port number:
Host : 35.220.150.0
Port : 3306
-
Access the Google Cloud SQL Instances page.
-
Locate the hostname of the master and the replica instance under Public IP address column.
The Google Cloud MySQL port value is 3306 by default.
You will specify these while creating your Hevo Pipeline.
2. Retrieve the username and password
To retrieve your username and password, or create a new user to connect to Hevo, read Create a User and Grant Privileges.
3. Retrieve the database names
-
Access the Google Cloud SQL Instances page and click on the Instance ID that you want to use.
-
In the left navigation pane, click Databases.
On this page, you can locate the name of the databases.
Perform the following steps to configure your Google Cloud MySQL Source:
-
Click PIPELINES in the Navigation Bar.
-
Click the Edge tab in the Pipelines List View and click + CREATE EDGE PIPELINE.
-
On the Create Pipeline page, under Source Configuration, do the following:
-
In the Selection screen, select Google Cloud MySQL.
-
In the Google Cloud MySQL screen, specify the following:
-
Source Name: A unique name for your Source, not exceeding 255 characters. For example, Google Cloud MySQL Source.
-
In the Connect to your MySQL section:
-
Database Host: The MySQL host’s IP address or DNS. This is the endpoint that you obtained in Step 5 above.
Note: For URL-based hostnames, exclude the http:// or https:// part. For example, if the hostname URL is http://mysql-replica.westeros.inc, enter mysql-replica.westeros.inc.
-
Database Port: The port on which your Google Cloud MySQL server listens for connections. This is the port number that you obtained in Step 5 above. Default value: 3306.
- Database User: The authenticated user who has the permissions to read tables in your database. For example, hevouser.
-
Database Password: The password of your database user.
- Database Names: The comma separated list of databases from where you want to replicate data. For example, demo1, demo2.
-
(Optional) In the Additional Settings section:
-
Use SSH: Enable this option to connect to Hevo using an SSH tunnel instead of directly connecting your MySQL database host to Hevo. This provides an additional level of security to your database by not exposing your MySQL setup to the public.
If this option is turned off, you must configure your Source to accept connections from Hevo’s IP address.
-
Use SSL: Enable this option to use an SSL-encrypted connection. Specify the following:
-
CA File: The file containing the SSL server certificate authority (CA).
-
Client Certificate: The client’s public key certificate file.
-
Client Key: The client’s private key file.
-
Click TEST & CONTINUE to test the connection to your Google Cloud MySQL Source. Once the test is successful, you can proceed to set up your Destination.
Data Type Mapping
Hevo maps the MySQL Source data type internally to a unified data type, referred to as the Hevo Data Type, in the table below. This data type is used to represent the Source data from all supported data types in a lossless manner.
The following table lists the supported MySQL data types and the corresponding Hevo data type to which they are mapped:
MySQL Data Type |
Hevo Data Type |
- BIT(1) - BOOLEAN - TINYINT(1) - TINYINT UNSIGNED(1) |
BOOLEAN |
- TINYINT(>1) - SMALLINT - TINYINT UNSIGNED(>1) |
SHORT |
- INT - MEDIUMINT - SMALLINT UNSIGNED - MEDIUMINT UNSIGNED - YEAR |
INTEGER |
- BIGINT - INT UNSIGNED - BIGINT UNSIGNED |
LONG |
- FLOAT(0-23) |
FLOAT |
- REAL - DOUBLE - FLOAT(24-53) |
DOUBLE |
- NUMERIC - DECIMAL |
DECIMAL |
- CHAR - VARCHAR - TINYTEXT - TEXT - MEDIUMTEXT - LONGTEXT - JSON - ENUM - SET |
VARCHAR |
- TIMESTAMP |
TIME_TZ |
- DATE |
DATE |
- TIME |
TIME |
- DATETIME |
TIMESTAMP |
- BIT(>1) - BINARY - VARBINARY - TINYBLOB - BLOB - MEDIUMBLOB - LONGBLOB |
BYTEARRAY |
At this time, the following MySQL data types are not supported by Hevo:
Note: If any of the Source objects contain data types that are not supported by Hevo, they are marked as unsupported during object configuration in the Pipeline.
Source Considerations
- MySQL does not generate log entries for cascading deletes. So, Hevo cannot capture these deletes for log-based Pipelines.
Limitations
-
Hevo only fetches tables from the MySQL database. It does not fetch other entities such as functions, stored procedures, views, and triggers.
-
Hevo does not set the metadata column __hevo_is_deleted__ to True for data deleted from the Source table using the TRUNCATE command. This action could result in a data mismatch between the Source and Destination tables.