Skip to contentManaged Kafka is live: Apache Kafka on AWS for half the cost of MSK

Sources

Connect MySQL as a source

Create a MySQL service account, turn on row-based binary logging, and connect the database in Artie so your pipeline replicates its changes.

Artie reads changes from the MySQL binary log (binlog). For MariaDB, see MariaDB.

Prerequisites

  • MySQL 5.7 or later, including MySQL 8
  • Amazon RDS or Aurora MySQL, Azure Database for MySQL, Google Cloud SQL for MySQL, or a self-hosted server
  • The host and port of the MySQL server
  • A database admin user to run the setup SQL
  • A database restart, if binary logging is off or binlog_format isn’t ROW
  • At least 24 hours of binlog retention

Setup

Run these three steps on the MySQL server before you add it in Artie.

1. Create a service account

Run this SQL as a database admin to create the user Artie signs in with. Pick the tab that matches the Authentication method you’ll choose in Artie.

This user signs in with a password:

setup.sql
CREATE USER 'artie' IDENTIFIED BY 'YOUR_PASSWORD';
-- SELECT is required for backfills.
-- REPLICATION CLIENT and REPLICATION SLAVE are required for Artie to read the binary log.
GRANT SELECT, REPLICATION CLIENT, REPLICATION SLAVE ON *.* TO 'artie';

Replace YOUR_PASSWORD with the password for this user.

2. Enable binary logging in ROW format

Binary logging must be on with binlog_format = ROW and binlog_row_image = FULL, the MySQL default. Artie reads every column from each row event, so with MINIMAL an event carries only the key columns and the columns the statement set, and with NOBLOB it leaves out BLOB and TEXT columns unless they identify the row or the statement changed them.

Create or update a parameter group for your database. For Aurora clusters, create a DB cluster parameter group instead. In Artie, set Host to the cluster’s writer endpoint. With a reader endpoint, Verify selected tables shows Binary logging is off.

  1. Create a parameter group

    In the AWS console, go to RDS > Parameter groups > Create parameter group. Select the family that matches your MySQL version.

  2. Set binlog_format to ROW

    Open the new parameter group, search for binlog_format, and set it to ROW.

  3. Apply the parameter group

    Associate the parameter group with your RDS instance or Aurora cluster, then reboot the database. On Aurora, reboot the writer instance.

RDS for MySQL writes binary logs only when automated backups are on. Set the backup retention period to a value greater than 0.

Run these queries on the MySQL server to check the result:

SQL
SHOW VARIABLES LIKE 'log_bin';
SHOW VARIABLES LIKE 'binlog_format';
SHOW VARIABLES LIKE 'binlog_row_image';

log_bin is ON, binlog_format is ROW, and binlog_row_image is FULL.

On MySQL 8, Artie converts streamed columns in other character sets, such as latin1, cp1251, utf16, gbk or sjis, to UTF-8. It reads each column’s character set from the binlog. MySQL 5.7 doesn’t log character sets. There, Artie streams columns that aren’t utf8, utf8mb4 or ascii unconverted, so non-ASCII characters arrive garbled, usually as �, and every character in a ucs2, utf16, utf16le or utf32 column arrives garbled. To stream these columns correctly, upgrade to MySQL 8 or convert the columns to utf8mb4.

A key value that converts differently no longer matches the row streamed before, so its updates and deletes miss that row until you backfill the table. Backfill a table if it was streaming before Artie Reader v0.1.707 and its primary key holds non-ASCII text in one of these character sets, or any value in ucs2, utf16, utf16le or utf32. Other values streamed before keep their garbled text until the row changes or you backfill.

3. Set binlog retention

Keep binary logs for at least 24 hours. If MySQL purges a binlog before Artie reads it, Artie restarts from the oldest binlog left and skips the changes in between. To recover them, backfill the affected tables.

The default retention is NULL, which purges binlogs as soon as possible. Set it to 24 hours:

SQL
CALL mysql.rds_set_configuration('binlog retention hours', 24);

With NULL or 0, the table check on Which tables do you want to stream? fails with this error:

Text
"binlog retention hours" must be set to a non-zero value

Add MySQL in Artie

Complete these steps in the pipeline setup flow in the Artie dashboard.

  1. Choose MySQL

    On Choose your source, select MySQL, then select Continue.

  2. Choose a network method

    On How would you like to connect your source?, select Allowlist Artie IPs, SSH tunnel or PrivateLink.

    PrivateLink needs an Enterprise plan and doesn’t work with role assumption. Connection options describes each method.

  3. Select your provider

    On Prepare MySQL, select where the database is hosted: Amazon Aurora / RDS, Azure Database for MySQL, Google Cloud SQL or Self-hosted / other.

    The step shows the setup SQL for that provider. Select Continue.

  4. Enter the host and port

    On Connect MySQL, enter the Host and Port. The port defaults to 3306.

  5. Enter the service account

    Under Authentication method, keep Static credentials, then enter the User and Password of your service account.

    To sign in with an IAM role instead, follow Set up role assumption.

  6. Select a TLS mode

    In TLS mode, select Disabled, TLS (preferred) or TLS (required). The default is Disabled.

    TLS (preferred) uses TLS when the server offers it and falls back to an unencrypted connection. TLS (required) also shows CA certificate (optional), Client certificate (optional) and Client key (optional).

If you pick an existing MySQL connector on Choose your source, the flow skips the network and Prepare MySQL steps. They were done when that connector was set up.

Connect MySQL also has Default schema (optional). Tables from that schema reach the destination without a schema-name prefix.

Verify the connection

Artie checks MySQL at two steps of the setup flow:

  1. On Connect MySQL, select Verify source. Artie signs in, and the step shows Source verified.
  2. On Which tables do you want to stream?, select your tables, then select Verify selected tables. Artie checks that binary logging is on, the REPLICATION CLIENT grant, replica health when Host is a replica, binlog retention and binlog_format. The step shows Tables verified.

This check doesn’t test REPLICATION SLAVE. Without that grant, the pipeline fails when it starts reading the binary log.

If a check fails, the step shows Couldn’t verify source or Couldn’t verify tables, and the button reads Try again. To continue without the check, select Verify later.

Optional settings

A pipeline replicates without any of these settings.

Set up role assumption

Role assumption lets Artie sign in to Amazon RDS or Aurora MySQL with an IAM role instead of a stored password. It works for backfills and binlog replication. Artie assumes the role and signs a new IAM authentication token for each connection, so you have no password to rotate.

Complete these steps in AWS, then in Artie:

  1. Enable IAM database authentication

    In the RDS console, modify the instance or Aurora cluster and set Database authentication to Password and IAM database authentication. See Enabling and disabling IAM database authentication.

  2. Create the IAM role

    Create a role in the AWS account that owns the database. Attach this policy, which allows rds-db:connect for the Artie user:

    JSON
    {
      "Version": "2012-10-17",
      "Statement": [
        {
          "Effect": "Allow",
          "Action": "rds-db:connect",
          "Resource": "arn:aws:rds-db:us-east-1:123456789012:dbuser:db-ABCDEFGHIJKLMNOPQRSTUVWXY/artie"
        }
      ]
    }

    Replace the Region, account ID, resource ID and user name with your own. The resource ID is the instance’s DbiResourceId or the Aurora cluster’s resource ID, which starts with db- or cluster-. It isn’t the database name.

    Add this trust policy so Artie can assume the role:

    JSON
    {
      "Version": "2012-10-17",
      "Statement": [
        {
          "Effect": "Allow",
          "Principal": {
            "AWS": "arn:aws:iam::788826912768:user/ci"
          },
          "Action": "sts:AssumeRole",
          "Condition": {
            "StringEquals": {
              "sts:ExternalId": "my-external-id"
            }
          }
        }
      ]
    }

    On a data plane you run yourself, trust the IAM identity your data plane runs as instead of Artie’s principal. Include the Condition block only when you enter an AWS external ID (optional) in Artie, and replace my-external-id with that exact value.

  3. Configure the connector

    On Connect MySQL in the pipeline setup flow, or when you edit the connector, set Authentication method to Role assumption. Enter the AWS role ARN and the database’s AWS region.

    Leave AWS external ID (optional) empty unless your trust policy has the Condition block.

Until AWS role ARN is set, the connector signs in with its password. Once it’s set, Artie stops using the password.

RDS accepts IAM tokens only over TLS, so role assumption always connects with TLS. Setting a role ARN switches TLS mode from Disabled to TLS (preferred), and Disabled leaves the list. CA certificate (optional) can’t be used with role assumption.

Role assumption works through an SSH tunnel, because Artie signs the token for the database’s own endpoint.

Enabling GTID

With global transaction IDs (GTIDs) on, Artie resumes replication from GTIDs instead of a binlog file and position. Artie needs both enforce_gtid_consistency and gtid_mode set to ON.

MySQL won’t switch gtid_mode straight from OFF to ON. Step through each mode in this order:

SQL
SET GLOBAL enforce_gtid_consistency = ON;
SET GLOBAL gtid_mode = OFF_PERMISSIVE;
SET GLOBAL gtid_mode = ON_PERMISSIVE;

Before you turn GTID mode on, run this query until it returns 0, so no transactions without a GTID are still running:

SQL
SHOW STATUS LIKE 'Ongoing_anonymous_transaction_count';

Then turn GTID mode on:

SQL
SET GLOBAL gtid_mode = ON;

Also set gtid_mode = ON and enforce_gtid_consistency = ON in my.cnf so the settings survive a restart.

If the server has replicas, run each step on every server before starting the next one. Wait for the replicas to catch up before setting gtid_mode = ON. See MySQL’s Enabling GTID transactions online.

Run these queries to check both settings:

SQL
SHOW VARIABLES LIKE 'gtid_mode';
SHOW VARIABLES LIKE 'enforce_gtid_consistency';

Both return ON.

Artie checks gtid_mode while it streams, so the dashboard has no GTID setting. Once Artie reaches a binlog file written after gtid_mode turned ON, it resumes from GTIDs on its next restart. If gtid_mode leaves ON, Artie goes back to binlog file and position.

Run gh-ost migrations

gh-ost changes a table’s schema by copying it to a ghost table, altering the copy, then swapping the two with one RENAME TABLE. Artie applies the ghost table’s schema changes and the swap from the binlog. The original table keeps replicating with its new columns, and the pipeline needs no restart.

Replicate from a read replica

Artie can read a replica’s binary log, if the replica writes the changes it replicates to that log. Artie reads the replica’s local binary log, never its relay log.

Configure the replica with these settings:

  • log_bin = ON
  • binlog_format = ROW
  • log_replica_updates = ON for MySQL 8.0.26 and later, or log_slave_updates = ON for MySQL 5.7 and 8.0.25 and earlier
  • A healthy replication connection and SQL applier
  • At least 24 hours of local binlog retention

Run these queries on the replica to check its configuration:

SQL
SHOW VARIABLES WHERE variable_name IN (
  'log_bin',
  'binlog_format',
  'log_replica_updates',
  'log_slave_updates'
);
SHOW REPLICA STATUS; -- Use SHOW SLAVE STATUS for MySQL 5.7 and MySQL 8.0.21 and earlier.
SHOW BINARY LOGS;

When Host is a replica, Verify selected tables checks that both replication threads run with no errors. It also checks that log_replica_updates or log_slave_updates is ON. A failed check shows an error such as:

Text
log_replica_updates must be ON, current value is "OFF"

A replica that keeps only relay logs can’t be used for change data capture (CDC). It can still serve backfills: on Connect MySQL, turn on Use a read replica for backfill? and enter the Replica host and Replica port. Change capture then stays on the primary.

Restrict the service account to Artie’s IP addresses

Create the user with a host pattern that matches Artie’s data plane IPs. Use netmask notation, because MySQL only understands CIDR host patterns such as 3.41.128.96/27 on 8.0.23 and later. On older versions, MySQL stores a CIDR pattern as a literal hostname that never matches, so logins fail.

This SQL creates the user for one Artie range in netmask notation:

SQL
-- 3.41.128.96/255.255.255.224 is the same range as 3.41.128.96/27
CREATE USER 'artie'@'3.41.128.96/255.255.255.224' IDENTIFIED BY 'YOUR_PASSWORD';
GRANT SELECT, REPLICATION CLIENT, REPLICATION SLAVE ON *.* TO 'artie'@'3.41.128.96/255.255.255.224';

Replace YOUR_PASSWORD with the password for this user. On Google Cloud SQL, a host mismatch shows a different error: see this user requires clear text authentication.

Backfill FLOAT columns as their shortest decimal

By default, backfills write each MySQL FLOAT value as its exact stored value. Replication writes the fewest digits that still represent the same stored value. To make backfills match replication, turn on Backfill MySQL FLOAT columns as their shortest decimal on Connect MySQL.

Troubleshooting

Each of these errors points to a setup step on the MySQL server or in Artie. Sign-in errors show on Verify source. Server setup errors show on Verify selected tables.

Binary logging is off

Verify selected tables shows this message:

Text
Binary logging is off. Self-hosted MySQL: set log_bin. RDS: set backup retention above 0. Aurora: set binlog_format to ROW on the writer. Cloud SQL: turn on point-in-time recovery.

Cause: The MySQL server writes no binary log, so Artie can’t read a binlog position.

Fix: Follow your provider’s tab in Enable binary logging in ROW format. On Aurora, also check that Host is the cluster’s writer endpoint.

Verify: Select Try again. The step shows Tables verified.

binlog_format must be set to ROW

Verify selected tables fails with this error:

Text
binlog_format must be set to 'ROW', current value is "MIXED"

Artie runs the same check when the pipeline starts replication. There, the error reads:

Text
'binlog_format' must be set to 'ROW', current value is 'MIXED'

Cause: The MySQL server’s binlog_format is MIXED or STATEMENT. Artie checks the value before it reads the binary log.

Fix: Set binlog_format to ROW, as in Enable binary logging in ROW format.

Verify: SHOW VARIABLES LIKE 'binlog_format'; returns ROW.

The Artie user needs REPLICATION CLIENT and REPLICATION SLAVE

Verify selected tables shows this message:

Text
The Artie user needs REPLICATION CLIENT and REPLICATION SLAVE. Grant both as shown in Prepare source.

Cause: MySQL denied the Artie user access when Artie read the binlog position.

Fix: Run the GRANT statement from Create a service account for your Artie user.

Verify: Select Try again. The step shows Tables verified.

Your database rejected the sign-in

Verify source shows this message:

Text
Your database rejected the sign-in. Check the username and password. With role assumption, check rds-db:connect and AWSAuthenticationPlugin.

Cause: MySQL returned Access denied for user for the Artie user.

Fix: With static credentials, re-enter the User and Password. With role assumption, check that the role’s policy allows rds-db:connect for this user, and that the user was created IDENTIFIED WITH AWSAuthenticationPlugin. Both are in Set up role assumption.

Verify: Select Try again. The step shows Source verified.

this user requires clear text authentication

On Google Cloud SQL, the connection check fails with an error containing this text:

Text
this user requires clear text authentication

Cause: The Artie user’s host pattern doesn’t match Artie’s IP address. Cloud SQL asks a login that matches no built-in user to sign in as a Cloud SQL IAM user, which Artie doesn’t support.

Fix: Check the user’s host pattern, as in Restrict the service account to Artie’s IP addresses.

Verify: Select Try again. The step shows Source verified.

Next steps

  • Connection options lists Artie’s IP addresses and covers SSH tunnels and PrivateLink.
  • Tables describes the table settings for your pipeline.
  • Backfills explains how Artie loads the rows already in your tables.

Was this page helpful?