HomeBlogAboutPricingContact🌐 中文
Back to HomeCloud Database
MySQL Cloud Database Integration Guide: Complete Tutorial for Migrating from Local to Cloud

MySQL Cloud Database Integration Guide: Complete Tutorial for Migrating from Local to Cloud

📑 Table of Contents

MySQL Cloud Database Integration Guide: Complete Tutorial for Migrating from Local to CloudMySQL Cloud Database Integration Guide: Complete Tutorial for Migrating from Local to Cloud

Is your MySQL database still running on that old server in the company's server room? Hard drives filling up, performance getting slower, worrying about crashes in the middle of the night. Moving to the cloud can solve most of these problems.

This article will teach you step by step how to migrate MySQL to the cloud. From choosing a platform, planning the migration, actual operations, to post-launch optimization—every step is explained in detail. Whether you're new to cloud or want to confirm you're doing it right, this guide will help.

Further reading: Cloud Database Complete Guide | Understanding cloud database basics



Why Move MySQL to the Cloud?

Advantages of Cloud MySQL

Moving MySQL to the cloud gives you these benefits:

1. No More Managing Hardware Hard drive failures, memory shortages, CPU bottlenecks—all handled by the cloud provider. You just focus on using and optimizing the database.

2. Elastic Scaling Traffic surge? A few clicks to upgrade specs. Promotion over? Scale back down. No need to plan purchases months in advance.

3. Automatic Backup and Disaster Recovery Cloud services have automatic backup by default, and you can set up cross-region replication. Even if an entire data center goes down, your data is safe.

4. High Availability Multi-AZ deployment, automatic failover—features that cost a fortune to build traditionally come with just a checkbox in the cloud.

5. Save Labor Costs No need for dedicated DBAs on 24/7 watch. The cloud provider's team handles the underlying operations.

When to Consider Migration

These situations are especially suitable for migration:

Pre-Migration Assessment Points

Migration isn't something you just do—evaluate these issues first:

1. How Much Data?

2. How Much Downtime is Acceptable?

3. Does the Application Need Changes?

4. Is Budget Sufficient?



Three Major Platform MySQL Service Comparison

All three major cloud platforms have MySQL managed services. Detailed comparison: AWS, GCP, Azure Database Complete Comparison

AWS RDS for MySQL

AWS's MySQL service is the most mature with the most options.

ItemDetails
MySQL Versions5.7, 8.0
Maximum Storage64 TB
Maximum Connections16,000 (depends on specs)
Read ReplicasUp to 15
Multi-AZ
Automatic BackupUp to 35 days

Pros:

Cons:

Suitable for: Enterprises already using AWS, scenarios needing maximum flexibility

GCP Cloud SQL for MySQL

Google Cloud's MySQL service is simple and easy to use. Detailed tutorial: Google Cloud Database Complete Tutorial

ItemDetails
MySQL Versions5.7, 8.0
Maximum Storage64 TB
Maximum Connections4,000 (depends on specs)
Read ReplicasUp to 10
High Availability
Automatic BackupUp to 365 days

Pros:

Cons:

Suitable for: Startups, enterprises needing Taiwan data residency

Azure Database for MySQL

Microsoft Azure's MySQL service, enterprise-oriented.

ItemDetails
MySQL Versions5.7, 8.0
Maximum Storage16 TB
Maximum Connections5,000 (depends on specs)
Read ReplicasUp to 10
High Availability
Automatic BackupUp to 35 days

Pros:

Cons:

Suitable for: Microsoft ecosystem enterprises, organizations with EA contracts

Feature and Pricing Comparison Table

Comparison ItemAWS RDSGCP Cloud SQLAzure MySQL
Minimum Monthly Cost (est.)~$15~$10~$12
Free Tier750 hours/month (12 months)None ($300 trial credits)750 hours (12 months)
Taiwan Data Center
Serverless OptionAurora ServerlessIn PreviewFlexible Server


MySQL Cloud Migration Steps

Time to actually migrate. Using GCP Cloud SQL as an example—other platforms have similar flows.

Step 1: Assess Your Current Database

Understand your current situation before migrating:

# Check database size
SELECT
    table_schema AS 'Database',
    ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS 'Size (MB)'
FROM information_schema.tables
GROUP BY table_schema;

# Check MySQL version
SELECT VERSION();

# Check character set settings
SHOW VARIABLES LIKE 'character_set%';
SHOW VARIABLES LIKE 'collation%';

# Check current connections
SHOW STATUS LIKE 'Max_used_connections';

Record this information:

Step 2: Choose Target Platform and Specs

Based on your assessment:

Choose Platform: Based on which cloud your company uses, budget, whether Taiwan data center is needed

Choose Specs:

Choose Region:

Step 3: Create Cloud MySQL Instance

Using GCP Cloud SQL as example:

  1. Log into GCP Console

    • Go to console.cloud.google.com
    • Select or create a project
  2. Create Cloud SQL Instance

    • Search for "Cloud SQL"
    • Click "Create Instance"
    • Select "MySQL"
  3. Configure Instance

    Instance ID: my-mysql-instance (custom)
    Password: Set root password
    MySQL Version: Select same version as source
    Region: asia-east1 (Taiwan)
    Zone: Single or multiple (high availability)
    
  4. Configure Machine Specs

    vCPU: Select based on needs
    Memory: Select based on needs
    Storage Type: SSD
    Storage Capacity: Set based on needs
    Enable automatic storage increases: Recommended
    
  5. Configure Connectivity

    Public IP: As needed (recommend Private IP)
    Authorized Networks: Add your IP
    
  6. Click "Create" and wait a few minutes

Step 4: Data Migration Methods

Several ways to migrate data:

Method 1: mysqldump (for small databases)

Simplest and most direct, suitable for databases under tens of GB.

# Export from source server
mysqldump -u root -p \
  --single-transaction \
  --routines \
  --triggers \
  --databases your_database > backup.sql

# Import to cloud MySQL
mysql -h [CLOUD_SQL_IP] -u root -p your_database < backup.sql

Method 2: Database Migration Service (for large databases)

All three platforms have migration services:

These services support continuous replication to minimize downtime.

Method 3: MySQL Replication (for zero downtime requirements)

Set up master-slave replication with cloud MySQL as a replica of your existing database:

-- Configure on source server
GRANT REPLICATION SLAVE ON *.* TO 'repl_user'@'%' IDENTIFIED BY 'password';

-- Configure on cloud MySQL
CHANGE MASTER TO
  MASTER_HOST='source_ip',
  MASTER_USER='repl_user',
  MASTER_PASSWORD='password',
  MASTER_LOG_FILE='mysql-bin.000001',
  MASTER_LOG_POS=123;

START SLAVE;

After synchronization, switch application connections and stop replication.

Step 5: Application Connection Setup

After data migration, update application connection settings:

Connection String Examples:

# Python (mysql-connector-python)
import mysql.connector

conn = mysql.connector.connect(
    host="[CLOUD_SQL_IP]",
    user="your_user",
    password="your_password",
    database="your_database",
    ssl_ca="server-ca.pem",
    ssl_cert="client-cert.pem",
    ssl_key="client-key.pem"
)
// Node.js (mysql2)
const mysql = require('mysql2');

const connection = mysql.createConnection({
  host: '[CLOUD_SQL_IP]',
  user: 'your_user',
  password: 'your_password',
  database: 'your_database',
  ssl: {
    ca: fs.readFileSync('server-ca.pem'),
    cert: fs.readFileSync('client-cert.pem'),
    key: fs.readFileSync('client-key.pem')
  }
});

GCP Cloud SQL Proxy (Recommended):

Using Cloud SQL Proxy is more secure and doesn't require public IP:

# Download and run Cloud SQL Proxy
./cloud-sql-proxy --port 3306 PROJECT_ID:REGION:INSTANCE_NAME

# Application connects to localhost:3306

Step 6: Testing and Validation

Thorough testing before going live:

1. Data Integrity Check

-- Compare row counts between source and target
SELECT COUNT(*) FROM your_table;

-- Check checksum
CHECKSUM TABLE your_table;

2. Performance Testing

# Benchmark with sysbench
sysbench oltp_read_write \
  --mysql-host=[CLOUD_SQL_IP] \
  --mysql-user=root \
  --mysql-password=xxx \
  --mysql-db=test \
  --tables=10 \
  --table-size=100000 \
  prepare

sysbench oltp_read_write \
  --mysql-host=[CLOUD_SQL_IP] \
  --mysql-user=root \
  --mysql-password=xxx \
  --mysql-db=test \
  --tables=10 \
  --table-size=100000 \
  --threads=16 \
  --time=60 \
  run

3. Application Testing


MySQL migration looks complicated? With experience it can go smoothly. Schedule migration consultation and let us help plan your migration strategy.



Cloud MySQL Best Practices

After moving to cloud, these settings and habits will make your MySQL run better.

Performance Tuning Tips

1. Adjust Buffer Pool Size

InnoDB buffer pool is key to performance. Cloud services usually auto-configure, but check:

SHOW VARIABLES LIKE 'innodb_buffer_pool_size';

Recommend setting to 70-80% of available memory.

2. Optimize Queries

Analyze slow queries with EXPLAIN:

EXPLAIN SELECT * FROM orders WHERE customer_id = 123;

Ensure frequently used queries utilize indexes.

3. Enable Query Cache (MySQL 5.7)

MySQL 8.0 removed query cache, but 5.7 can still use it:

SET GLOBAL query_cache_type = ON;
SET GLOBAL query_cache_size = 67108864;  -- 64MB

4. Connection Pool Settings

Use connection pooling on application side to avoid frequent connection creation:

# Python SQLAlchemy connection pool example
from sqlalchemy import create_engine

engine = create_engine(
    'mysql+pymysql://user:pass@host/db',
    pool_size=10,
    max_overflow=20,
    pool_recycle=3600
)

Security Settings (SSL, IAM, Firewall)

1. Enforce SSL Connections

-- Create user that only allows SSL connections
CREATE USER 'app_user'@'%' REQUIRE SSL;
GRANT ALL PRIVILEGES ON your_db.* TO 'app_user'@'%';

2. Principle of Least Privilege

Don't use root for all applications:

-- Create users with only necessary privileges
CREATE USER 'readonly'@'%' IDENTIFIED BY 'password';
GRANT SELECT ON your_db.* TO 'readonly'@'%';

CREATE USER 'app'@'%' IDENTIFIED BY 'password';
GRANT SELECT, INSERT, UPDATE, DELETE ON your_db.* TO 'app'@'%';

3. Network Access Control

Backup and Disaster Recovery Strategy

1. Automatic Backup Settings

All three platforms have automatic backup:

2. Point-in-Time Recovery (PITR)

If data is accidentally deleted, restore to a specific point in time:

# GCP example
gcloud sql instances clone SOURCE_INSTANCE TARGET_INSTANCE \
  --point-in-time '2025-01-15T10:00:00.000Z'

3. Cross-Region Backup

Important systems should enable cross-region backup or read replicas for entire region failure protection.

Monitoring and Alert Configuration

1. Key Metrics Monitoring

Set alerts for these metrics:

2. Slow Query Log

Enable slow query log to find SQL that needs optimization:

SET GLOBAL slow_query_log = 'ON';
SET GLOBAL long_query_time = 2;  -- Queries over 2 seconds are slow

3. Use Cloud Monitoring Tools



Common Problems and Solutions

Connection Troubleshooting

Problem: Can't connect to cloud MySQL

Checklist:

  1. Is IP whitelist configured?
  2. Is firewall open for port 3306?
  3. Is user account configured correctly?
  4. Is SSL certificate path correct?
# Test connection
mysql -h [CLOUD_SQL_IP] -u root -p --ssl-mode=REQUIRED

# If can't connect, test network first
telnet [CLOUD_SQL_IP] 3306

Problem: SSL certificate error

# Re-download certificates
# GCP
gcloud sql ssl client-certs create CLIENT_CERT_NAME \
  --instance=INSTANCE_NAME

# Verify certificate paths
ls -la /path/to/certs/

Performance Issue Diagnosis

Problem: Queries getting slow

-- View currently executing queries
SHOW FULL PROCESSLIST;

-- View slowest queries
SELECT * FROM performance_schema.events_statements_summary_by_digest
ORDER BY SUM_TIMER_WAIT DESC LIMIT 10;

-- Check for lock waits
SHOW ENGINE INNODB STATUS;

Problem: Connection limit reached

-- Check current connections
SHOW STATUS LIKE 'Threads_connected';

-- Check max connections setting
SHOW VARIABLES LIKE 'max_connections';

-- Check connections by user
SELECT user, host, COUNT(*) as connections
FROM information_schema.processlist
GROUP BY user, host;

Solutions:

Cost Optimization Tips

1. Choose Right Specs

Don't start with the biggest specs. Start small, monitor for a few weeks, then decide on upgrades.

2. Use Committed Use Discounts

If committed to long-term use, buying 1 or 3 year commitments can save 30-50%.

3. Save on Dev Environments

4. Monitor Idle Resources

Regularly check for unused instances, snapshots, and backups.



Free MySQL Cloud Options

Limited budget? Consider these free options. Detailed list: Free MySQL Cloud Plans List

PlanetScale Free Plan

ItemFree Quota
Storage5 GB
Reads1 billion/month
Writes10 million/month
Branches2 (1 production + 1 development)

PlanetScale is a MySQL-compatible serverless database with generous free quota. Downside is it doesn't support foreign key constraints.

Three Platform Free Tiers

PlatformFree ContentDuration
AWS RDSdb.t2.micro 750 hours/month12 months
GCP Cloud SQLNone ($300 trial credits)90 days for credits
Azure MySQL750 hours/month12 months

AWS and Azure free tiers are for new accounts' first 12 months, then you pay. GCP has no free Cloud SQL, but $300 trial credits can last a while.



FAQ

Can existing MySQL queries be used directly?

Most can. Cloud MySQL uses standard MySQL engine with compatible SQL syntax. But note:

Will cloud MySQL have better performance?

Not necessarily. Performance depends on:

With same specs, performance should be similar. Cloud's advantage is ability to quickly upgrade specs.

Will migration interrupt service?

Depends on which method you choose:

For production environments, recommend replication or DMS.

How do I change connection strings after migration?

Main changes:



Conclusion

Moving MySQL to cloud isn't difficult, but needs proper planning.

Migration Checklist

Key Takeaways

  1. Choose the right platform: Based on your cloud ecosystem, whether Taiwan data residency is needed
  2. Choose the right migration method: Small databases use mysqldump, large databases use DMS or replication
  3. Test thoroughly: Always test integrity and performance before going live
  4. Set up monitoring: Continuously monitor after launch, catch issues early


Want to Switch Platforms but Worried About the Hassle?

MySQL cloud migration involves many details:

CloudSwap Cloud Migration Consultation can help you:

Migration Assessment: Analyze existing database, evaluate migration feasibility and risks ✅ Platform Recommendation: Recommend most suitable cloud platform based on your needs ✅ Cost Estimation: Estimate migration costs and monthly operating expenses ✅ Migration Planning: Create detailed migration plan, minimize downtime ✅ Launch Support: Full assistance during migration process, ensure smooth launch

We have rich MySQL cloud migration experience, providing full assistance from assessment to launch.

Schedule Migration Consultation

Click to schedule 30-minute free consultation

Whether it's your first migration or you want to optimize existing architecture, we can provide professional advice.



Further Reading



References

  1. AWS RDS for MySQL Documentation
  2. Google Cloud SQL for MySQL Documentation
  3. Azure Database for MySQL Documentation
  4. MySQL 8.0 Reference Manual
  5. Percona - MySQL Performance Tuning
  6. PlanetScale Documentation

Need Professional Cloud Advice?

Whether you're evaluating cloud platforms, optimizing existing architecture, or looking for cost-saving solutions, we can help

Book Free Consultation

Cloud DatabaseAWSAzureKubernetes
Previous
Cloud Native 12 Factor Complete Guide: 12 Principles for Building Scalable Cloud Native Apps【2025】
Next
What is Cloud Database? 2025 Complete Guide | Free Plans, Platform Comparison, Setup Tutorial