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.
Overview
Section titled “Overview”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:
- Enable binary logging with row-based format
- Create a dedicated user with appropriate permissions
- Configure network access to allow Sync or Swim connections
- Gather connection credentials
Prerequisites
Section titled “Prerequisites”- 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)
Understanding Binary Log (Binlog)
Section titled “Understanding Binary Log (Binlog)”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:
| Setting | Required Value | Purpose |
|---|---|---|
log_bin | ON | Enables binary logging |
binlog_format | ROW | Logs actual row data (not just SQL) |
binlog_row_image | FULL | Logs complete before/after images |
Database Setup
Section titled “Database Setup”This section assumes you already have a MySQL server running and have administrative access.
1. Check Current Binlog Configuration
Section titled “1. Check Current Binlog Configuration”Connect to your MySQL database using an administrative user:
# Connect as root or admin usermysql -u root -p
# Or specify hostmysql -u your_admin_user -h your_database_host -pCheck the current binlog configuration:
-- Check if binlog is enabledSHOW 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 fileSHOW 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:
# 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 filesmysql --help | grep -A1 "Default options"Edit the configuration file:
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnfAdd or modify these settings in the [mysqld] section:
[mysqld]# Enable binary logginglog_bin = mysql-binserver-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 replicationbinlog_expire_logs_days = 7max_binlog_size = 100M
# For MySQL 8.0+, use this instead of binlog_expire_logs_days# binlog_expire_logs_seconds = 604800Restart MySQL:
# Ubuntu/Debiansudo systemctl restart mysql
# RHEL/CentOSsudo systemctl restart mysqld
# macOS (Homebrew)brew services restart mysqlVerify the configuration:
-- Connect and verifymysql -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';3. Create a Database (Optional)
Section titled “3. Create a Database (Optional)”You can either create a new database or use an existing one:
-- Option A: Create a new databaseCREATE DATABASE your_database_name CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- Option B: Use an existing database (skip to step 4)4. Create a Dedicated User
Section titled “4. Create a Dedicated User”Create a user with the necessary permissions for data synchronization and binlog access:
-- Create the userCREATE USER 'sync_user'@'%' IDENTIFIED BY 'your_secure_password';
-- Grant database privilegesGRANT 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 changesFLUSH 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 compatibilityALTER USER 'sync_user'@'%' IDENTIFIED WITH mysql_native_password BY 'your_secure_password';FLUSH PRIVILEGES;5. Configure Network Access (If Required)
Section titled “5. Configure Network Access (If Required)”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:
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnfFind 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.100Restart MySQL:
sudo systemctl restart mysqlConfigure firewall (if applicable):
# Ubuntu/Debian with ufwsudo ufw allow from 192.168.1.100 to any port 3306
# RHEL/CentOS with firewalldsudo firewall-cmd --zone=public --add-port=3306/tcp --permanentsudo firewall-cmd --reload6. Verify the Setup
Section titled “6. Verify the Setup”Test the connection from the Sync or Swim server:
# Test connectionmysql -u sync_user -p -h your_database_host your_database_name
# If successful, you should see the MySQL prompt# mysql>
# Test replication privilegesSHOW MASTER STATUS;
# Should return binlog file and position# If you get an error, check that REPLICATION CLIENT was granted
# Test permissionsSHOW TABLES;\qConnection Details
Section titled “Connection Details”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
For existing RDS MySQL instances, you’ll need to enable binlog replication and create a user.
1. Enable Binary Logging
Section titled “1. Enable Binary Logging”RDS MySQL needs specific parameter group settings for binlog access.
Create or modify a Parameter Group:
- Navigate to RDS > Parameter Groups in AWS Console
- Create a new parameter group or modify your existing one
- Set these parameters:
binlog_format=ROWbinlog_row_image=FULL
Enable Automated Backups:
Binary logging requires automated backups to be enabled:
- Navigate to your RDS instance
- Click Modify
- Under Backup, set Backup retention period to at least 1 day
- Apply the changes (may require a reboot)
Apply the Parameter Group:
- Navigate to your RDS instance
- Click Modify
- Select your custom parameter group
- Apply immediately or during next maintenance window
2. Configure Security Group
Section titled “2. Configure Security Group”- Navigate to EC2 > Security Groups
- Find the security group assigned to your RDS instance
- Add an inbound rule:
- Type: MySQL/Aurora
- Protocol: TCP
- Port: 3306
- Source: Your Sync or Swim server’s IP address
3. Create Application User
Section titled “3. Create Application User”Connect to your RDS instance:
mysql -h your-rds-endpoint.region.rds.amazonaws.com \ -u your_master_user \ -pCreate a user with replication privileges:
-- Create userCREATE USER 'sync_user'@'%' IDENTIFIED BY 'your_secure_password';
-- Grant database privilegesGRANT ALL PRIVILEGES ON your_database_name.* TO 'sync_user'@'%';
-- Grant replication privilegesGRANT REPLICATION SLAVE ON *.* TO 'sync_user'@'%';GRANT REPLICATION CLIENT ON *.* TO 'sync_user'@'%';
FLUSH PRIVILEGES;4. Verify Binlog Configuration
Section titled “4. Verify Binlog Configuration”-- Connect as sync_usermysql -h your-rds-endpoint.region.rds.amazonaws.com -u sync_user -p
-- Verify binlog is enabledSHOW VARIABLES LIKE 'log_bin';
-- Verify row-based formatSHOW VARIABLES LIKE 'binlog_format';
-- Check current positionSHOW MASTER STATUS;Connection Details
Section titled “Connection Details”You’ll need:
- Hostname: Found in RDS console (e.g.,
your-instance.abc123.us-east-1.rds.amazonaws.com) - Port:
3306(default) - Database: Your database name
- Username:
sync_user - Password: The password you set
- SSL:
true(recommended for RDS)
1. Enable Binary Logging
Section titled “1. Enable Binary Logging”- Navigate to your Cloud SQL instance in the Cloud SQL Console
- Click Edit
- Expand Flags
- Add or verify these flags:
binlog_format=ROWbinlog_row_image=FULL
- Click Save
Note: Binary logging is automatically enabled when you enable point-in-time recovery.
Enable Point-in-Time Recovery:
- Go to Backups
- Enable Point-in-time recovery
- This automatically enables binary logging
2. Configure Network Access
Section titled “2. Configure Network Access”- Go to Connections > Networking
- Under Authorized networks, add your Sync or Swim server’s IP address
3. Create User
Section titled “3. Create User”Connect to your Cloud SQL instance:
# Using gcloudgcloud sql connect your-instance-name --user=root
# Or using mysql with public IPmysql -h your-instance-ip -u root -pCreate the user:
CREATE USER 'sync_user'@'%' IDENTIFIED BY 'your_secure_password';GRANT ALL PRIVILEGES ON your_database_name.* TO 'sync_user'@'%';GRANT REPLICATION SLAVE ON *.* TO 'sync_user'@'%';GRANT REPLICATION CLIENT ON *.* TO 'sync_user'@'%';FLUSH PRIVILEGES;Connection Details
Section titled “Connection Details”- Hostname: Found in Cloud SQL console (public IP or Cloud SQL Proxy)
- Port:
3306 - Database: Your database name
- Username:
sync_user - Password: The password you set
- SSL:
true(recommended)
1. Configure Server Parameters
Section titled “1. Configure Server Parameters”- Navigate to your Azure Database for MySQL in the Azure Portal
- Go to Server parameters
- Set these parameters:
binlog_format=ROWbinlog_row_image=FULL
- Click Save
Note: Azure Database for MySQL Flexible Server has binlog enabled by default with automated backups.
2. Configure Firewall
Section titled “2. Configure Firewall”- Go to Networking or Connection security
- Add a firewall rule with your Sync or Swim server’s IP address
3. Create User
Section titled “3. Create User”Connect using the admin user:
mysql -h your-server.mysql.database.azure.com \ -u your_admin_user@your-server \ -pCreate the user:
CREATE USER 'sync_user'@'%' IDENTIFIED BY 'your_secure_password';GRANT ALL PRIVILEGES ON your_database_name.* TO 'sync_user'@'%';GRANT REPLICATION SLAVE ON *.* TO 'sync_user'@'%';GRANT REPLICATION CLIENT ON *.* TO 'sync_user'@'%';FLUSH PRIVILEGES;Connection Details
Section titled “Connection Details”- Hostname:
your-server.mysql.database.azure.com - Port:
3306 - Database: Your database name
- Username:
sync_user@your-server(Azure format) - Password: The password you set
- SSL:
true(required by Azure)
Configuring Sync or Swim
Section titled “Configuring Sync or Swim”Once your MySQL database is set up, configure Sync or Swim through the web UI:
- Navigate to
/settingsin the Sync or Swim web interface - Click “Add Service”
- Select “MySQL” as the adapter type
- 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
- Click “Test Connection” to verify
- Click “Create Service” to save
The system will automatically validate that binlog is properly configured when you test the connection.
Security Best Practices
1. Use Strong Passwords
Section titled “1. Use Strong Passwords”- Minimum 16 characters
- Mix of uppercase, lowercase, numbers, and special characters
- Use a password manager
- Rotate passwords regularly
2. Limit Network Access
Section titled “2. Limit Network Access”- 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/0in production environments
3. Enable SSL/TLS
Section titled “3. Enable SSL/TLS”Always use SSL for connections, especially over the internet:
-- Verify SSL is availableSHOW VARIABLES LIKE '%ssl%';
-- Check if user requires SSLSELECT 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;4. Use Dedicated Users
Section titled “4. Use Dedicated Users”- Create a specific user for Sync or Swim
- Grant only necessary privileges
- Use different users for different environments
5. Regular Backups
Section titled “5. Regular Backups”Self-hosted MySQL:
# Automated backup scriptmysqldump -u sync_user -p your_database_name > backup_$(date +%Y%m%d).sqlCloud Providers:
- Ensure automated backups are enabled
- Point-in-time recovery is recommended (also enables binlog)
- Test restore procedures regularly
6. Monitor Binlog Usage
Section titled “6. Monitor Binlog Usage”-- Check binlog filesSHOW BINARY LOGS;
-- Check disk usage for binlogsSELECT SUM(FILE_SIZE) / 1024 / 1024 AS 'Binlog Size (MB)'FROM information_schema.FILESWHERE FILE_TYPE = 'BINLOG';Troubleshooting
Connection Refused
Section titled “Connection Refused”Symptoms: Can't connect to MySQL server
Solutions:
- Verify MySQL is running:
sudo systemctl status mysql - Check firewall rules allow port 3306
- Verify
bind-addressin MySQL configuration - Check cloud provider security groups/firewall rules
Access Denied
Section titled “Access Denied”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@servernameformat
Binlog Not Enabled
Section titled “Binlog Not Enabled”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
Replication Permission Denied
Section titled “Replication Permission Denied”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'@'%';
SSL Connection Required
Section titled “SSL Connection Required”Symptoms: SSL connection error or Connections using insecure transport are prohibited
Solutions:
- Set
ssl: truein Sync or Swim configuration - Ensure MySQL is configured for SSL:
SHOW VARIABLES LIKE '%ssl%';
Authentication Plugin Issues (MySQL 8.0+)
Section titled “Authentication Plugin Issues (MySQL 8.0+)”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
Binlog Retention
Section titled “Binlog Retention”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.7SET GLOBAL expire_logs_days = 7;Monitor Replication Lag
Section titled “Monitor Replication Lag”-- Check binary log positionSHOW MASTER STATUS;
-- Monitor connectionsSHOW PROCESSLIST;Index Optimization
Section titled “Index Optimization”Ensure tables being synchronized have appropriate indexes, especially on:
- Primary keys
- Foreign keys used in relationships
- Fields used for filtering
-- Check table indexesSHOW INDEX FROM your_table_name;Additional Resources
Section titled “Additional Resources”- MySQL Official Documentation
- MySQL Binary Log Documentation
- Amazon RDS for MySQL
- Google Cloud SQL for MySQL
- Azure Database for MySQL
Support
Section titled “Support”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)