Set up a MySQL or MariaDB destination¶
The Replicator Service writes to a MySQL or MariaDB database through an ODBC driver on the Stelo VM. It creates the destination tables and their indexes, loads baselines and snapshots, and applies incremental changes with SQL.
Supported configurations¶
| Supported | |
|---|---|
| MySQL | MySQL and MariaDB. SingleStore is handled as MySQL, through the SingleStore ODBC driver. For managed services (such as Amazon RDS or Aurora, Azure Database for MySQL or Google Cloud SQL), ask Stelo Support. |
| Driver on the Stelo VM | MySQL Connector/ODBC (8.0, 8.4 or 9.5), the MariaDB ODBC driver, or the SQDR bundled MySQL driver (MySQL Enterprise only). See Databases. |
| Snapshot replication | Yes. |
| Incremental replication | Yes, from any source with a Capture Agent. |
| Apply methods | Batch, Merge and Sequence (see Choosing the apply method). |
| Authentication | Remote Credentials: a MySQL user and its password. |
| Encryption | SSL/TLS: SSLMODE with MySQL Connector/ODBC, FORCETLS with the MariaDB driver. See Connection strings. |
Docker
The SQDR container includes MySQL Connector/ODBC 8.0 and 8.4 and the MariaDB ODBC driver (see ODBC drivers in the container).
Prepare the database¶
The database administrator creates the database the tables go into and the user the Replicator Service connects as. MySQL has no schemas inside a database: the tables are created directly in a database, and the destination has a Database but no Object Schema. The privileges follow from the SQL the Replicator Service runs (see What the Replicator Service runs on the database).
Create the database and the user¶
Run as a user with the CREATE USER privilege and the right to grant the privileges below (for example root):
CREATE DATABASE mydb CHARACTER SET utf8mb4;
CREATE USER 'sqdruser'@'sqdrhost' IDENTIFIED BY 'mypassword';
GRANT SELECT, INSERT, UPDATE, DELETE,
CREATE, DROP, ALTER, INDEX, REFERENCES, CREATE TEMPORARY TABLES
ON mydb.* TO 'sqdruser'@'sqdrhost';
Replace mydb, sqdruser, mypassword and sqdrhost (the Stelo VM's host name or address, or % for any host)
with yours. A utf8mb4 database stores every Unicode character; the older utf8 (utf8mb3) has no 4-byte characters
such as emoji. Grant the same privileges on each other database that subscriptions write to. Why each privilege is
needed, and what's enough for tables you create yourself: see Privileges.
Server settings¶
- Storage engine. The tables use the server's default storage engine, InnoDB unless it was changed. Keep a transactional engine: the Replicator Service commits each batch of changes as one transaction and rolls it back when a change fails (see When a change can't be applied).
max_allowed_packet. Each statement must fit in the server'smax_allowed_packet. The native loader sends many rows in oneINSERT, and large LOB values make single rows large. If the server refuses a statement as too large, raisemax_allowed_packet, or choose Insert using ODBC for the subscription.
Network¶
The Stelo VM must reach the MySQL server's port, 3306 by default, and the user must be allowed to connect from the
Stelo VM's host (the host part of 'sqdruser'@'sqdrhost').
Create the destination¶
Install the driver, then create the destination as described in Create a destination, with these choices:
-
Install the ODBC driver on the Stelo VM: MySQL Connector/ODBC (8.0, 8.4 or 9.5) from MySQL, or the MariaDB ODBC driver from MariaDB. For the SQDR bundled MySQL driver (MySQL Enterprise only) and SingleStore, see Other MySQL drivers.
Docker
The SQDR container includes MySQL Connector/ODBC 8.0 and 8.4 and the MariaDB ODBC driver.
-
Name: choose the DBMS Type MySQL (also for MariaDB and SingleStore).
-
Connection: choose ODBC Driver and the driver, then the Template for it, and fill in the fields (see Connection string). Always set the database: it's where Merge creates its merge tables.
-
Authentication: Remote Credentials with the user and its password. Click Verify.
- Tick Advanced to check the defaults: on the Default step, Database is where new subscriptions create their tables (by default, the connection string's database). See Defaults.
Verify tests the connection, not the privileges (see Test the privileges).
Connection string¶
| Driver | Connection string | Notes |
|---|---|---|
| MySQL Connector/ODBC | SERVER=myhostip;PORT=3306;DATABASE=mydb;FOUND_ROWS=1;NO_SSPS=1 |
Keep FOUND_ROWS=1: otherwise MySQL reports an UPDATE that sets a row to its current values as 0 rows changed, and the Batch and Sequence apply methods flag it as a row not found (see How Batch works). Keep NO_SSPS=1 (no server-side prepared statements). TLS with certificate validation: add SSLMODE=VERIFY_CA;SSLCA=C:\certs\ca-bundle.pem. |
| MariaDB ODBC driver | SERVER=myhostip;PORT=3306;DATABASE=mydb;OPTIONS=2;CHARSET=utf8 |
OPTIONS=2 is the MariaDB driver's equivalent of FOUND_ROWS=1; keep it. TLS: add FORCETLS=1;SSLCA=C:\certs\ca-bundle.pem. |
| SQDR bundled MySQL driver | HostName=myhostip;PortNumber=3306;Database=mydb |
MySQL Enterprise only. |
Always set the database (DATABASE= or Database=): it's the connection's default database. For MySQL and MariaDB
sources, the Replicator Service adds NO_CACHE=1 (unless your string sets it), so large results don't have to fit in
memory.
Other MySQL drivers¶
- SQDR bundled MySQL driver (MySQL Enterprise only): installed with SQDR. See Connection string.
- SingleStore ODBC driver, for SingleStore: see SingleStore.
Group settings for MySQL and MariaDB¶
When you create an incremental group to this destination, choose the DML Replication method (see Apply):
- Batch (the default), Merge and Sequence are all available. Merge is the fastest for high volumes
(see Choosing the apply method). MySQL has no
MERGEstatement: Merge loads each member's changes into a permanentSQDRWT_<id>table in the connection's default database, then runs aDELETEand anINSERT ... SELECT. The user needsCREATEandDROPthere (see Create the database and the user). It needs a key on every member: members without one are applied with inserts only (see Tables without a usable key). - For SingleStore, ask Stelo Support before you choose Merge (see SingleStore).
Check the destination¶
After the first baseline of the incremental group (for snapshots, after the first run):
-
Group status. On the Groups page, the group shows Actively monitoring and applying change data (see Group status). If a member failed, its replication events show the MySQL error;
command denied to usernames the statement that lacks a privilege. To see the user's privileges:SHOW GRANTS FOR 'sqdruser'@'sqdrhost'; -
Rows at the destination. Compare a table's row count with the source:
SELECT COUNT(*) FROM mydb.mytable; -
Changes. Change a few rows at the source; they're applied with the group's next poll (the Poll Interval; see Scheduling). Query the rows again to see them.
What the Replicator Service runs on the database¶
The privileges in Prepare the database follow from these statements:
| When | Statements |
|---|---|
| A subscription is saved or a baseline starts (depending on its Destination DDL Options) | DROP TABLE and CREATE TABLE for the destination table. CREATE TABLE has no ENGINE clause, so the server's default storage engine is used. |
| Before a baseline or snapshot copies the data | TRUNCATE TABLE, or, with Delete existing data before replication, DELETE FROM ... LIMIT n in batches (see Baseline Replication Options). |
| During the copy | With Use native-loader function, if available (the default), multi-row INSERT INTO ... VALUES (...), (...), ... statements, one per block of rows; with Insert using ODBC, INSERT with ODBC parameters. |
| Around the copy | CREATE INDEX and DROP INDEX ... ON for the index on the replication key (suffix IR) and the source indexes you replicate; ALTER TABLE ... ADD CONSTRAINT ... PRIMARY KEY and DROP PRIMARY KEY for Allow UPSERT members and replicated primary keys; ALTER TABLE ... ADD CONSTRAINT ... FOREIGN KEY for replicated foreign keys. See The key at the destination. |
| Applying changes with Batch or Sequence | INSERT, UPDATE ... WHERE <key> and DELETE ... WHERE <key>, one row at a time. |
| Applying changes with Merge | DROP TABLE and CREATE TABLE SQDRWT_<id> (a permanent table, created in the connection's default database) the first time a member is merged after the group starts; TRUNCATE TABLE and a multi-row INSERT for each batch; then DELETE <table> FROM <table> JOIN SQDRWT_<id> ... and INSERT INTO <table> SELECT ... FROM SQDRWT_<id> ..., with ON DUPLICATE KEY UPDATE when the destination table has a primary key or unique index on the key. See The MERGE statement. |
| With Merge In Place | A permanent merge table next to the destination table, named with the Decoration, handled the same way. |
| ALTER processing | ALTER TABLE ... ADD COLUMN, MODIFY, DROP COLUMN and RENAME COLUMN. ADD Copy loads a work table SQDRCP_<id> (CREATE TEMPORARY TABLE, or a regular table when the group allows checkpoint/restart) in the destination table's database and updates the destination table from it with UPDATE ... INNER JOIN. |
Data types¶
The Replicator Service maps the source columns to the types the driver reports; see Data type mapping and its Per-database notes. For MySQL:
- Dates and times. Columns without a reported precision get a default one;
timestampanddatetimehave up to 6 fractional digits. A nullableTIMESTAMPdestination column is createdNULL, so a NULL isn't stored as the load time. - Integers. Unsigned integers map to types that hold their whole range (see How the default mapping works).
- Bits and times. The sizes of
BIT(n)andTIME(n)source columns are read from the database; a MySQLBIT(n)staysbit(n). - Identity columns. The Replicator Service doesn't create
AUTO_INCREMENTcolumns, and inserts the source's values.
Limitations¶
- Merge tables stay in the database. The
SQDRWT_<id>tables are permanent (a MySQL temporary table can't be read twice in one statement, which the merge needs). Drop those of members you delete by hand (see The merge table). Don't create tables with these names. - Merge and unique keys. Whether the destination table has a primary key or unique index on the key columns is checked when the member is set up for incremental replication. Without one, Merge deletes the rows it's about to insert or update, then inserts them, so no duplicates are created.
- Merge needs a key. Members without key columns are applied row by row with inserts only.
- Allow disable/enable indexes has no effect on MySQL (SQL Server and Oracle only).
- Truncate. MySQL doesn't truncate a table that another table's foreign key references; use Delete existing data before replication for such tables.
Troubleshooting¶
Problems and messages, with their causes and fixes, are in Troubleshooting › MySQL and MariaDB.
Related¶
- More about preparing a MySQL or MariaDB destination
- Prepare a MySQL or MariaDB database (as a source)
- MySQL documentation: Privileges provided by MySQL, TRUNCATE TABLE, max_allowed_packet