Skip to main content

MySQL

Features

FeatureSupportedNotes
Full Refresh SyncYes
Incremental - Append SyncYes
Replicate Incremental DeletesYes
CDCYes
SSL SupportYes
SSH Tunnel ConnectionYes
NamespacesYesEnabled by default
ArraysYesByte arrays are not supported yet

The MySQL source does not alter the schema present in your database. Depending on the destination connected to this source, however, the schema may be altered. See the destination's documentation for more details.

Troubleshooting

There may be problems with mapping values in MySQL's datetime field to other relational data stores. MySQL permits zero values for date/time instead of NULL which may not be accepted by other data stores. To work around this problem, you can pass the following key value pair in the JDBC connector of the source setting zerodatetimebehavior=Converttonull.

Some users reported that they could not connect to Amazon RDS MySQL or MariaDB. This can be diagnosed with the error message: Cannot create a PoolableConnectionFactory. To solve this issue add enabledTLSProtocols=TLSv1.2 in the JDBC parameters.

Getting Started (Airbyte Cloud)

On Airbyte Cloud, only TLS connections to your MySQL instance are supported. Other than that, you can proceed with the open-source instructions below.

Getting Started (Airbyte Open-Source)

Requirements

  1. MySQL Server 8.0, 5.7, or 5.6.
  2. Create a dedicated read-only Airbyte user with access to all tables needed for replication.

1. Make sure your database is accessible from the machine running Airbyte

This is dependent on your networking setup. The easiest way to verify if Airbyte is able to connect to your MySQL instance is via the check connection tool in the UI.

2. Create a dedicated read-only user with access to the relevant tables (Recommended but optional)

This step is optional but highly recommended to allow for better permission control and auditing. Alternatively, you can use Airbyte with an existing user in your database.

To create a dedicated database user, run the following commands against your database:

CREATE USER 'airbyte'@'%' IDENTIFIED BY 'your_password_here';

The right set of permissions differ between the STANDARD and CDC replication method. For STANDARD replication method, only SELECT permission is required.

GRANT SELECT ON <database name>.* TO 'airbyte'@'%';

For CDC replication method, SELECT, RELOAD, SHOW DATABASES, REPLICATION SLAVE, REPLICATION CLIENT permissions are required.

GRANT SELECT, RELOAD, SHOW DATABASES, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'airbyte'@'%';

Your database user should now be ready for use with Airbyte.

3. Set up CDC

For STANDARD replication method this is not applicable. If you select the CDC replication method then only this is required. Please read the section on CDC below for more information.

4. That's it!

Your database user should now be ready for use with Airbyte.

Change Data Capture (CDC)

  • If you need a record of deletions and can accept the limitations posted below, you should be able to use CDC for MySQL.
  • If your data set is small, and you just want snapshot of your table in the destination, consider using Full Refresh replication for your table instead of CDC.
  • If the limitations prevent you from using CDC and your goal is to maintain a snapshot of your table in the destination, consider using non-CDC incremental and occasionally reset the data and re-sync.
  • If your table has a primary key but doesn't have a reasonable cursor field for incremental syncing (i.e. updated_at), CDC allows you to sync your table incrementally.

CDC Limitations

  • Make sure to read our CDC docs to see limitations that impact all databases using CDC replication.
  • Our CDC implementation uses at least once delivery for all change records.

1. Enable binary logging

You must enable binary logging for MySQL replication. The binary logs record transaction updates for replication tools to propagate changes. You can configure your MySQL server configuration file with the following properties, which are described in below:

server-id                  = 223344
log_bin = mysql-bin
binlog_format = ROW
binlog_row_image = FULL
binlog_expire_log_seconds = 864000
  • server-id : The value for the server-id must be unique for each server and replication client in the MySQL cluster. The server-id should be a non-zero value. If the server-id is already set to a non-zero value, you don't need to make any change. You can set the server-id to any value between 1 and 4294967295. For more information refer mysql doc
  • log_bin : The value of log_bin is the base name of the sequence of binlog files. If the log_bin is already set, you don't need to make any change. For more information refer mysql doc
  • binlog_format : The binlog_format must be set to ROW. For more information refer mysql doc
  • binlog_row_image : The binlog_row_image must be set to FULL. It determines how row images are written to the binary log. For more information refer mysql doc
  • binlog_expire_log_seconds : This is the number of seconds for automatic binlog file removal. We recommend 864000 seconds (10 days) so that in case of a failure in sync or if the sync is paused, we still have some bandwidth to start from the last point in incremental sync. We also recommend setting frequent syncs for CDC.

2. Enable GTIDs (Optional)

Global transaction identifiers (GTIDs) uniquely identify transactions that occur on a server within a cluster. Though not required for a Airbyte MySQL connector, using GTIDs simplifies replication and enables you to more easily confirm if primary and replica servers are consistent. For more information refer mysql doc

  • Enable gtid_mode : Boolean that specifies whether GTID mode of the MySQL server is enabled or not. Enable it via mysql> gtid_mode=ON
  • Enable enforce_gtid_consistency : Boolean that specifies whether the server enforces GTID consistency by allowing the execution of statements that can be logged in a transactionally safe manner. Required when using GTIDs. Enable it via mysql> enforce_gtid_consistency=ON

Note

When a sync runs for the first time using CDC, Airbyte performs an initial consistent snapshot of your database. Airbyte doesn't acquire any table locks (for tables defined with MyISAM engine, the tables would still be locked) while creating the snapshot to allow writes by other database clients. But in order for the sync to work without any error/unexpected behaviour, it is assumed that no schema changes are happening while the snapshot is running.

Connection via SSH Tunnel

Airbyte has the ability to connect to a MySQl instance via an SSH Tunnel. The reason you might want to do this because it is not possible (or against security policy) to connect to the database directly (e.g. it does not have a public IP address).

When using an SSH tunnel, you are configuring Airbyte to connect to an intermediate server (a.k.a. a bastion sever) that does have direct access to the database. Airbyte connects to the bastion and then asks the bastion to connect directly to the server.

Using this feature requires additional configuration, when creating the source. We will talk through what each piece of configuration means.

  1. Configure all fields for the source as you normally would, except SSH Tunnel Method.
  2. SSH Tunnel Method defaults to No Tunnel (meaning a direct connection). If you want to use an SSH Tunnel choose SSH Key Authentication or Password Authentication.
    1. Choose Key Authentication if you will be using an RSA private key as your secret for establishing the SSH Tunnel (see below for more information on generating this key).
    2. Choose Password Authentication if you will be using a password as your secret for establishing the SSH Tunnel.
  3. SSH Tunnel Jump Server Host refers to the intermediate (bastion) server that Airbyte will connect to. This should be a hostname or an IP Address.
  4. SSH Connection Port is the port on the bastion server with which to make the SSH connection. The default port for SSH connections is 22, so unless you have explicitly changed something, go with the default.
  5. SSH Login Username is the username that Airbyte should use when connection to the bastion server. This is NOT the MySQl username.
  6. If you are using Password Authentication, then SSH Login Username should be set to the password of the User from the previous step. If you are using SSH Key Authentication leave this blank. Again, this is not the MySQl password, but the password for the OS-user that Airbyte is using to perform commands on the bastion.
  7. If you are using SSH Key Authentication, then SSH Private Key should be set to the RSA Private Key that you are using to create the SSH connection. This should be the full contents of the key file starting with -----BEGIN RSA PRIVATE KEY----- and ending with -----END RSA PRIVATE KEY-----.

Generating an SSH Key Pair

The connector expects an RSA key in PEM format. To generate this key:

ssh-keygen -t rsa -m PEM -f myuser_rsa

This produces the private key in pem format, and the public key remains in the standard format used by the authorized_keys file on your bastion host. The public key should be added to your bastion host to whichever user you want to use with Airbyte. The private key is provided via copy-and-paste to the Airbyte connector configuration screen, so it may log in to the bastion.

Data Type Mapping

MySQL data types are mapped to the following data types when synchronizing data. You can check the test values examples here. If you can't find the data type you are looking for or have any problems feel free to add a new test!

MySQL TypeResulting TypeNotes
bit(1)boolean
bit(>1)base64 binary string
booleanboolean
tinyint(1)boolean
tinyintnumber
smallintnumber
mediumintnumber
intnumber
bigintnumber
floatnumber
doublenumber
decimalnumber
binarystring
blobstring
datestringISO 8601 date string. ZERO-DATE value will be converted to NULL. If column is mandatory, convert to EPOCH.
datetime, timestampstringISO 8601 datetime string. ZERO-DATE value will be converted to NULL. If column is mandatory, convert to EPOCH.
timestringISO 8601 time string. Values are in range between 00:00:00 and 23:59:59.
yearyear stringDoc
char, varchar with non-binary charsetstring
char, varchar with binary charsetbase64 binary string
tinyblobbase64 binary string
blobbase64 binary string
mediumblobbase64 binary string
longblobbase64 binary string
binarybase64 binary string
varbinarybase64 binary string
tinytextstring
textstring
mediumtextstring
longtextstring
jsonserialized json stringE.g. {"a": 10, "b": 15}
enumstring
setstringE.g. blue,green,yellow
geometrybase64 binary string

If you do not see a type in this list, assume that it is coerced into a string. We are happy to take feedback on preferred mappings.

Changelog

VersionDatePull RequestSubject
0.5.132022-06-2113945Aligned datatype test
0.5.122022-06-1713864Updated stacktrace format for any trace message errors
0.5.112022-05-0312544Prevent source from hanging under certain circumstances by adding a watcher for orphaned threads.
0.5.102022-04-2912480Query tables with adaptive fetch size to optimize JDBC memory consumption
0.5.92022-04-0611729Bump mina-sshd from 2.7.0 to 2.8.0
0.5.62022-02-2110242Fixed cursor for old connectors that use non-microsecond format. Now connectors work with both formats
0.5.52022-02-1810242Updated timestamp transformation with microseconds
0.5.42022-02-1110251bug Source MySQL CDC: sync failed when has Zero-date value in mandatory column
0.5.22021-12-146425MySQL CDC sync fails because starting binlog position not found in DB
0.5.12021-12-138582Update connector fields title/description
0.5.02021-12-117970Support all MySQL types
0.4.132021-12-038335Source-MySql: do not check cdc required param binlog_row_image for standard replication
0.4.122021-12-018371Fixed incorrect handling "\n" in ssh key
0.4.112021-11-198047Source MySQL: transform binary data base64 format
0.4.102021-11-157820Added basic performance test
0.4.92021-11-027559Correctly process large unsigned short integer values which may fall outside java's Short data type capability
0.4.82021-09-166093Improve reliability of processing various data types like decimals, dates, datetime, binary, and text
0.4.72021-09-306585Improved SSH Tunnel key generation steps
0.4.62021-09-296510Support SSL connection
0.4.52021-09-176146Added option to connect to DB via SSH
0.4.12021-07-234956Fix log link
0.3.72021-06-093179Add AIRBYTE_ENTRYPOINT for Kubernetes support
0.3.62021-06-093966Fix excessive logging for CDC method
0.3.52021-06-073890Fix CDC handle tinyint(1) and boolean types
0.3.42021-06-043846Fix max integer value failure
0.3.32021-06-023789MySQL CDC poll wait 5 minutes when not received a single record
0.3.22021-06-013757MySQL CDC poll 5s to 5 min
0.3.12021-06-013505Implemented MySQL CDC
0.3.02021-04-212990Support namespaces
0.2.52021-04-152899Fix bug in tests
0.2.42021-03-282600Add NCHAR and NVCHAR support to DB and cursor type casting
0.2.32021-03-262611Add an optional jdbc_url_params in parameters
0.2.22021-03-262460Destination supports destination sync mode
0.2.12021-03-182488Sources support primary keys
0.2.02021-03-092238Protocol allows future/unknown properties
0.1.102021-02-021887Migrate AbstractJdbcSource to use iterators
0.1.92021-01-251746Fix NPE in State Decorator
0.1.82021-01-191724Fix JdbcSource handling of tables with same names in different schemas
0.1.72021-01-141655Fix JdbcSource OOM
0.1.62021-01-081307Migrate Postgres and MySQL to use new JdbcSource
0.1.52020-12-111267Support incremental sync
0.1.42020-11-301046Add connectors using an index YAML file