Skip to content

MySQL Setup

This guide will walk you through configuring your existing MySQL database for use with Sync or Swim. It covers both self-hosted MySQL databases and cloud-hosted services like Amazon RDS, Google Cloud SQL, and Azure Database for MySQL.

Sync or Swim connects to your MySQL database to synchronize data bidirectionally with other services. The MySQL adapter supports real-time Change Data Capture (CDC) through MySQL’s binary log (binlog), similar to how PostgreSQL uses Write-Ahead Logging (WAL).

You’ll need to:

  1. Enable binary logging with row-based format
  2. Create a dedicated user with appropriate permissions
  3. Configure network access to allow Sync or Swim connections
  4. Gather connection credentials
  • Existing MySQL database (version 5.7 or higher, MySQL 8.0+ recommended)
  • Administrative access to the database server
  • Network access to the database server from where Sync or Swim is running
  • Connection details (hostname, port, admin credentials)

MySQL’s binary log records all changes to your database. Sync or Swim uses this log for real-time change detection, similar to how it uses PostgreSQL’s WAL.

Key binlog settings required:

SettingRequired ValuePurpose
log_binONEnables binary logging
binlog_formatROWLogs actual row data (not just SQL)
binlog_row_imageFULLLogs complete before/after images

This section assumes you already have a MySQL server running and have administrative access.

Connect to your MySQL database using an administrative user:

Terminal window
# Connect as root or admin user
mysql -u root -p
# Or specify host
mysql -u your_admin_user -h your_database_host -p

Check the current binlog configuration:

-- Check if binlog is enabled
SHOW VARIABLES LIKE 'log_bin';
-- Check binlog format (must be ROW)
SHOW VARIABLES LIKE 'binlog_format';
-- Check binlog row image (should be FULL)
SHOW VARIABLES LIKE 'binlog_row_image';
-- Check current binlog file
SHOW MASTER STATUS;

2. Enable Binary Logging (If Not Already Enabled)

Section titled “2. Enable Binary Logging (If Not Already Enabled)”

If binlog is not enabled or not configured correctly, you’ll need to modify your MySQL configuration.

Find your MySQL config file:

/etc/mysql/mysql.conf.d/mysqld.cnf
# Common locations:
# RHEL/CentOS: /etc/my.cnf
# macOS (Homebrew): /opt/homebrew/etc/my.cnf
# Windows: C:\ProgramData\MySQL\MySQL Server 8.0\my.ini
# Show where MySQL is looking for config files
mysql --help | grep -A1 "Default options"

Edit the configuration file:

Terminal window
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

Add or modify these settings in the [mysqld] section:

[mysqld]
# Enable binary logging
log_bin = mysql-bin
server-id = 1
# Use row-based logging (required for CDC)
binlog_format = ROW
# Log full row images (required for before/after data)
binlog_row_image = FULL
# Recommended settings for replication
binlog_expire_logs_days = 7
max_binlog_size = 100M
# For MySQL 8.0+, use this instead of binlog_expire_logs_days
# binlog_expire_logs_seconds = 604800

Restart MySQL:

Terminal window
# Ubuntu/Debian
sudo systemctl restart mysql
# RHEL/CentOS
sudo systemctl restart mysqld
# macOS (Homebrew)
brew services restart mysql

Verify the configuration:

-- Connect and verify
mysql -u root -p
-- Should return 'ON'
SHOW VARIABLES LIKE 'log_bin';
-- Should return 'ROW'
SHOW VARIABLES LIKE 'binlog_format';
-- Should return 'FULL'
SHOW VARIABLES LIKE 'binlog_row_image';

You can either create a new database or use an existing one:

-- Option A: Create a new database
CREATE DATABASE your_database_name CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- Option B: Use an existing database (skip to step 4)

Create a user with the necessary permissions for data synchronization and binlog access:

-- Create the user
CREATE USER 'sync_user'@'%' IDENTIFIED BY 'your_secure_password';
-- Grant database privileges
GRANT ALL PRIVILEGES ON your_database_name.* TO 'sync_user'@'%';
-- Grant replication privileges (required for binlog CDC)
GRANT REPLICATION SLAVE ON *.* TO 'sync_user'@'%';
GRANT REPLICATION CLIENT ON *.* TO 'sync_user'@'%';
-- Apply the changes
FLUSH PRIVILEGES;

For MySQL 8.0+ with caching_sha2_password (default):

If you encounter authentication issues, you may need to use the older authentication method:

-- Alternative: Use mysql_native_password for compatibility
ALTER USER 'sync_user'@'%' IDENTIFIED WITH mysql_native_password BY 'your_secure_password';
FLUSH PRIVILEGES;

If Sync or Swim will connect from a different server, ensure MySQL accepts remote connections.

Check current bind address:

SHOW VARIABLES LIKE 'bind_address';

If it shows 127.0.0.1, you’ll need to modify the configuration:

Edit MySQL configuration:

Terminal window
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

Find and modify the bind-address setting:

[mysqld]
# Allow connections from any IP (adjust for security)
bind-address = 0.0.0.0
# Or bind to a specific interface
# bind-address = 192.168.1.100

Restart MySQL:

Terminal window
sudo systemctl restart mysql

Configure firewall (if applicable):

Terminal window
# Ubuntu/Debian with ufw
sudo ufw allow from 192.168.1.100 to any port 3306
# RHEL/CentOS with firewalld
sudo firewall-cmd --zone=public --add-port=3306/tcp --permanent
sudo firewall-cmd --reload

Test the connection from the Sync or Swim server:

Terminal window
# Test connection
mysql -u sync_user -p -h your_database_host your_database_name
# If successful, you should see the MySQL prompt
# mysql>
# Test replication privileges
SHOW MASTER STATUS;
# Should return binlog file and position
# If you get an error, check that REPLICATION CLIENT was granted
# Test permissions
SHOW TABLES;
\q

You’ll need:

  • Hostname: Your database server’s IP or hostname
  • Port: 3306 (default)
  • Database: Your database name
  • Username: sync_user
  • Password: The password you set
  • SSL: Configure based on your setup

Once your MySQL database is set up, configure Sync or Swim through the web UI:

  1. Navigate to /settings in the Sync or Swim web interface
  2. Click “Add Service”
  3. Select “MySQL” as the adapter type
  4. Enter your connection details:
    • Hostname: Your database host
    • Port: 3306 (default)
    • Database: Your database name
    • Username: sync_user
    • Password: Your secure password
    • SSL: Enable for cloud providers
  5. Click “Test Connection” to verify
  6. Click “Create Service” to save

The system will automatically validate that binlog is properly configured when you test the connection.

Security Best Practices
  • Minimum 16 characters
  • Mix of uppercase, lowercase, numbers, and special characters
  • Use a password manager
  • Rotate passwords regularly
  • Use firewall rules to restrict access to known IP addresses
  • For cloud providers, use VPC/Private endpoints when possible
  • Never use 0.0.0.0/0 in production environments

Always use SSL for connections, especially over the internet:

-- Verify SSL is available
SHOW VARIABLES LIKE '%ssl%';
-- Check if user requires SSL
SELECT user, host, ssl_type FROM mysql.user WHERE user = 'sync_user';

Require SSL for the sync user:

ALTER USER 'sync_user'@'%' REQUIRE SSL;
FLUSH PRIVILEGES;
  • Create a specific user for Sync or Swim
  • Grant only necessary privileges
  • Use different users for different environments

Self-hosted MySQL:

Terminal window
# Automated backup script
mysqldump -u sync_user -p your_database_name > backup_$(date +%Y%m%d).sql

Cloud Providers:

  • Ensure automated backups are enabled
  • Point-in-time recovery is recommended (also enables binlog)
  • Test restore procedures regularly
-- Check binlog files
SHOW BINARY LOGS;
-- Check disk usage for binlogs
SELECT SUM(FILE_SIZE) / 1024 / 1024 AS 'Binlog Size (MB)'
FROM information_schema.FILES
WHERE FILE_TYPE = 'BINLOG';
Troubleshooting

Symptoms: Can't connect to MySQL server

Solutions:

  • Verify MySQL is running: sudo systemctl status mysql
  • Check firewall rules allow port 3306
  • Verify bind-address in MySQL configuration
  • Check cloud provider security groups/firewall rules

Symptoms: Access denied for user 'sync_user'@'...'

Solutions:

  • Verify username and password are correct
  • Check user exists: SELECT user, host FROM mysql.user;
  • Ensure connecting from correct host
  • For Azure, use username@servername format

Symptoms: Binary logging is not enabled during Sync or Swim setup

Solutions:

  • Verify binlog is ON: SHOW VARIABLES LIKE 'log_bin';
  • Check binlog format: SHOW VARIABLES LIKE 'binlog_format';
  • For cloud providers, enable automated backups
  • Restart MySQL after configuration changes

Symptoms: Access denied; you need the REPLICATION SLAVE privilege

Solutions:

  • Grant replication privileges:
    GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'sync_user'@'%';
    FLUSH PRIVILEGES;
  • Verify grants: SHOW GRANTS FOR 'sync_user'@'%';

Symptoms: SSL connection error or Connections using insecure transport are prohibited

Solutions:

  • Set ssl: true in Sync or Swim configuration
  • Ensure MySQL is configured for SSL: SHOW VARIABLES LIKE '%ssl%';

Symptoms: Authentication plugin 'caching_sha2_password' cannot be loaded

Solutions:

  • Use mysql_native_password:
    ALTER USER 'sync_user'@'%' IDENTIFIED WITH mysql_native_password BY 'password';
  • Or update your MySQL client library
Performance Considerations

Configure appropriate binlog retention to balance disk usage and recovery needs:

-- MySQL 8.0+
SET GLOBAL binlog_expire_logs_seconds = 604800; -- 7 days
-- MySQL 5.7
SET GLOBAL expire_logs_days = 7;
-- Check binary log position
SHOW MASTER STATUS;
-- Monitor connections
SHOW PROCESSLIST;

Ensure tables being synchronized have appropriate indexes, especially on:

  • Primary keys
  • Foreign keys used in relationships
  • Fields used for filtering
-- Check table indexes
SHOW INDEX FROM your_table_name;

If you encounter issues not covered in this guide, please contact Sync or Swim support with:

  • MySQL version: SELECT VERSION();
  • Binlog status: SHOW VARIABLES LIKE 'log_bin';
  • Error messages from the Sync or Swim logs
  • Connection details (hostname, port, database name - not passwords!)
  • Cloud provider and service tier (if applicable)