Connect SPSync to MySQL or MariaDB
This guide covers MySQL and MariaDB you run yourself, Azure Database for MySQL, Amazon RDS
and Aurora MySQL, and Google Cloud SQL for MySQL. SPSync uses one destination kind, mysql,
and the same connection string shape for all of them.
Before you start
Section titled “Before you start”- MySQL or MariaDB, reachable from the machine that runs SPSync.
- Nothing to install on that machine. SPSync connects with a pure Python driver, PyMySQL, so no client library is needed.
- Rights to create a database and a user.
Create the database and a least-privilege user
Section titled “Create the database and a least-privilege user”On MySQL and MariaDB a schema is a database. SPSync loads into a database named by
dataset_name (for example sync) and uses a second database, sync_staging, while it
merges a round. Create both and give one user full rights on only those two. The script is
from the MySQL documentation and has not been run here against a test server.
CREATE DATABASE sync;CREATE DATABASE sync_staging;CREATE USER 'spsync_loader'@'%' IDENTIFIED BY 'use-a-long-random-password';GRANT ALL PRIVILEGES ON sync.* TO 'spsync_loader'@'%';GRANT ALL PRIVILEGES ON sync_staging.* TO 'spsync_loader'@'%';Replace '%' with the address SPSync connects from if you can. CREATE VIEW is covered by
ALL PRIVILEGES on those databases, which reporting views need.
Creating the two databases first, as above, is the safe route. A grant on a database name
also lets a user create that database, so the script printed by spsync mysql-grants (below)
creates only the account and its grants.
Allow SPSync to reach it
Section titled “Allow SPSync to reach it”MySQL listens on TCP 3306. On the desktop app and a self-hosted server, the connection starts from that machine. For the Azure managed application, allow the address it connects out from, or put the database on the same virtual network, instead of opening it to the internet.
- Self-hosted: set
bind-addressso the server listens on the right interface and allow the SPSync address in the host firewall. - Azure Database for MySQL (Flexible Server): on the server’s Networking page, add a firewall rule for the address, or use private access in a virtual network and run SPSync inside it.
- Amazon RDS and Aurora MySQL: add an inbound rule for port 3306 to the security group, with the source written as /32. On Aurora use the cluster (writer) endpoint.
- Google Cloud SQL: under Connections, add the address as an authorized network, or use the Cloud SQL Auth Proxy.
Encrypt the connection
Section titled “Encrypt the connection”PyMySQL tries TLS when the server offers it, but it carries on without it when it cannot.
To require TLS and check the server certificate, add ssl_ca with the path to the CA file
and no other ssl_ parameter:
mysql+pymysql://spsync_loader:PASSWORD@HOST:3306/sync?ssl_ca=/path/to/ca.pemPyMySQL has no ssl_mode setting, so using one makes the connection fail before it starts.
Do not add ssl_verify_identity=true next to ssl_ca: it makes PyMySQL discard the CA path
and turns checking off. ssl_ca on its own already requires TLS and verifies the host name.
A private CA or a client certificate. The ssl_ca path in the string works where the
machine has that file, but the Azure edition has no way to upload one. The
alternative is to paste the certificate. On the Destination screen, paste the PEM into CA
certificate bundle, and for a client certificate paste Client certificate and Client
private key (an unencrypted PEM key). SPSync then checks the server certificate and its host
name. SPSync keeps the PEM as a stored secret: in the operating system keychain on the desktop app, as a Key Vault reference in the Azure edition, and it never shows it again after you save. At run time SPSync writes it to an owner-only temporary file because the database driver needs a path, and removes the file when the run ends. Leave the ssl_ parameters out of the string when you use these fields:
SPSync refuses a string that sets them as well.
With no CA pasted, SPSync checks the server certificate against the operating system’s trusted roots. The TLS fields also work with the token authentication modes (Entra, AWS IAM, Google Cloud IAM); a client certificate pasted here cannot be combined with the client_certificate authentication mode, which sets its own, so use one or the other.
Clearing Verify the server certificate turns checking off. The connection stays encrypted but SPSync no longer checks who it is talking to. Use it only while you fix the certificate. SPSync logs a destination_tls_verification_disabled warning on every run, Test connection reports “connected (warning: …)” and spsync doctor prints a WARNING. With checking off the connection is still encrypted.
This is a preview. SPSync’s automated tests check how these settings are handed to PyMySQL
through SQLAlchemy, and nothing connects to a MySQL server with them. It has not been run
against a MySQL or MariaDB server with a private CA. spsync doctor prints a destination-tls line with the trust mode.
Where the host needs its own CA:
- Azure Database for MySQL: use the DigiCert Global Root G2 certificate Microsoft
publishes. The retired Single Server SKU used the Baltimore root and wanted
user@servernameas the login. Flexible Server takes a plain user name. - Amazon RDS and Aurora: download the regional RDS CA bundle and point
ssl_caat it. - Google Cloud SQL: through the Auth Proxy connect to
127.0.0.1:3306with nossl_parameters, because the proxy handles TLS. For a direct connection, usessl_ca,ssl_certandssl_keyfrom the client certificate you download from the instance’s Connections page.
Through an SSH tunnel
Section titled “Through an SSH tunnel”If the database is reachable only through a jump host, SPSync can open an SSH tunnel to that host for each run, forward a local port to the database, and close the tunnel when the run ends. This is a preview: it is tested against a real SSH server in the SPSync test suite, but it has not been run against a live MySQL or MariaDB server behind a customer’s jump host.
-
On a machine you trust, read the jump host’s host key fingerprint. This prints a line containing
SHA256:followed by 43 characters:Terminal window ssh-keyscan -t ed25519 bastion.example.com | ssh-keygen -lf -SPSync asks the server for an ed25519 host key first, then ECDSA, then RSA, so pin the fingerprint of the first of those the server has. If you are unsure, run
ssh-keyscanwithout-tand pin every fingerprint it prints. -
In the connection string, give the database’s address as the jump host sees it, for example
db.internal:3306. SPSync rewrites the address to the local port while the tunnel is open; the string you save is not changed. -
On the Destination screen, tick Reach the database through an SSH bastion and fill in the host, port, user and fingerprint, then paste a private key (and its passphrase) or enter a password. The key is kept in the computer’s keychain and is not shown again.
-
In the CLI, add an
ssh_tunnelblock to the destination in the config file, as below.export-configdoes not write it. With the admin MCP server, the assistant can set the host, port, user and fingerprint, and you enter the key or password on the secure entry page.
destination: kind: mysql connection_string_env: SPSYNC_DSN ssh_tunnel: host: bastion.example.com port: 22 # optional, 22 by default user: spsync host_key_fingerprints: - "SHA256:<the fingerprint from step 1>" private_key_env: keychain:spsync/bastion-key # or file:/path/to/key, or an environment variable name # passphrase_env: BASTION_KEY_PASSPHRASE # only if the key has one # password_env: BASTION_PASSWORD # instead of private_key_envThe host key is always checked. If the jump host presents a key that is not in
host_key_fingerprints, SPSync stops before it sends any credential, and there is no setting
that turns the check off. Keep a second fingerprint in the list while you rotate the host
key. SPSync ignores ~/.ssh/config, known_hosts and any SSH agent: it uses exactly what is
configured here. The key, its passphrase and the password are never written to the config
file or to the control store; they are stored as keychain or Key Vault references, and a
plain environment variable name works for the CLI.
Test connection and spsync doctor open the same tunnel as a run and say so in their
result: connected through SSH tunnel, then the user, host and port, and host key pinned.
The read-only MCP server (spsync mcp serve) opens its own connection to the replica and does
not go through the tunnel.
Traffic between SPSync and the jump host is encrypted by SSH. Because the tunnel changes the
host in the connection string to the loopback address, a MySQL connection that checks the
server certificate (the default with the TLS fields, which have no certificate-name override
for MySQL) fails unless the certificate lists 127.0.0.1. SPSync does not
switch verification off for you: either give the server a certificate that lists that address,
or keep TLS on without the name check and accept that the last hop, from the jump host to the
database, is only as private as that network.
Authentication SPSync supports today
Section titled “Authentication SPSync supports today”A database password in the connection string works on every host. Other sign-in methods depend on the host:
| Host | Sign-in methods |
|---|---|
| Azure Database for MySQL (Flexible Server) | Preview, not verified live: Microsoft Entra ID: managed identity, DefaultAzureCredential, a service principal with a certificate, or with a client secret as a fallback. The user name is the Entra principal. |
| Amazon RDS for MySQL, Aurora MySQL | Preview, not verified live: IAM database authentication. SPSync generates the token from the AWS credential chain, a fresh one for each connection. |
| Google Cloud SQL for MySQL | Preview, not verified live: IAM database authentication on a direct connection (a Google access token from Application Default Credentials), or the Cloud SQL Auth Proxy with --auto-iam-authn, which needs no SPSync setting. |
| Self-hosted MySQL and MariaDB, Cloud SQL direct | A TLS client certificate (REQUIRE X509), with or without a password. Tested on MySQL, not on MariaDB. |
| MariaDB | Password (a client certificate is not tested on MariaDB). MariaDB has no Entra or IAM sign-in. |
The Entra and IAM rows are available in preview and not verified live against a real Azure Database for MySQL, RDS or Aurora MySQL, or Cloud SQL for MySQL server. The client certificate method is tested on MySQL; it is not tested on MariaDB.
The signed-in desktop user is not offered for MySQL yet.
An Entra or IAM token is sent to MySQL as the password over the mysql_clear_password
plugin, which sends it as plain text inside the connection. SPSync therefore refuses to send
one unless TLS verifies the server: it needs ssl_ca (if you leave it out, SPSync uses the
operating system’s trusted roots), and it rejects ssl_disabled, ssl_check_hostname=false, ssl_verify_cert and
ssl_verify_identity for these modes. The token exchange itself has not been run against a
real Azure, RDS or Cloud SQL server yet.
Choose the method on the Destination screen’s Authentication list, or in the config file. Only identifiers and the names of environment variables go in the config, never a secret:
destination: kind: mysql connection_string_env: SPSYNC_DSN # mysql+pymysql://spsync-mi@HOST:3306/sync?ssl_ca=/path/ca.pem dataset_name: sync auth: mode: entra_managed_identity # or entra_default, entra_service_principal_certificate, # entra_service_principal_secret, aws_iam, gcp_iam, # client_certificateFor client_certificate, name the files through environment variables:
certificate_path_env, private_key_path_env and optionally root_certificate_path_env. The
private key stays in its file. The connection string then needs the user and no password
unless the account also requires one.
Run spsync mysql-grants --auth-mode <password|azure_entra|aws_iam|gcp_iam|x509> --account NAME --dataset sync to print the SQL for a least-privilege account for your sign-in method.
It grants table, index and view rights on sync and sync_staging only. SPSync’s
automated tests run a load under exactly the password and X.509 versions of that script on
MySQL and MariaDB. The Azure, AWS and Google lines come from vendor documentation and have not
been run here, and no live run against Azure, RDS or Cloud SQL has been recorded yet.
spsync doctor reports the sign-in method and the account the server sees
(CURRENT_USER()), and warns when the connection string does not verify the server.
Connect from SPSync
Section titled “Connect from SPSync”The connection string names the driver. HOST is your server’s name:
mysql+pymysql://spsync_loader:PASSWORD@HOST:3306/sync?ssl_ca=/path/to/ca.pemURL-encode any @, : or / in the password.
-
Desktop app: open the Destination screen, choose MySQL, paste the string into Connection string and choose Test connection.
-
CLI:
Terminal window export SPSYNC_DSN='mysql+pymysql://spsync_loader:PASSWORD@HOST:3306/sync?ssl_ca=/path/to/ca.pem'spsync export-config --output replication.yaml \--site-url https://contoso.sharepoint.com/sites/x --list Projects \--pipeline-name spsync_dev --prefix dev \--destination-kind mysql --connection-string-env SPSYNC_DSN --dataset-name sync \--client-id <entra-app-client-id> -
AI assistant: with the admin MCP server connected, ask for the destination requirements, then let the assistant create the destination. You enter the string on the secure entry page.
MariaDB
Section titled “MariaDB”The same string and driver work. MariaDB is wire-compatible, and SPSync runs its test suite against both MySQL 8.4 and MariaDB 11.
What Test connection and doctor check
Section titled “What Test connection and doctor check”Both open a connection with the string and run SELECT 1. A pass means the host is
reachable, TLS worked and the password is accepted. It does not prove the user can create
tables. spsync doctor reports the same probe as destination-connectivity.
Common errors
Section titled “Common errors”| What you see | What it means and the fix |
|---|---|
Can't connect to MySQL server or timed out |
A firewall, security group or authorized network is blocking port 3306, or the host is wrong. |
Access denied for user |
Wrong password, or the user was created for a different host than SPSync connects from. |
Access denied for user ... to database |
The user has no rights on sync or sync_staging. Run the grants above. |
the connection string sets ssl_ca |
You gave SPSync a CA or client certificate and the string also sets an ssl_ parameter. Remove it from the string. |
unexpected keyword argument 'ssl_mode' |
PyMySQL has no ssl_mode. Use ssl_ca instead. |
Data too long for column 'state' |
A replica created by an older release. Run the two statements in “Fix a replica created by an older release” below once. |
Fix a replica created by an older release
Section titled “Fix a replica created by an older release”If you see Data too long for column 'state', run these two statements once, in the
database named by dataset_name:
ALTER TABLE _dlt_pipeline_state MODIFY `state` LONGTEXT NOT NULL;ALTER TABLE _dlt_version MODIFY `schema` LONGTEXT NOT NULL;These statements are not run by SPSync’s own tests.