Database Migration
This guide walks through migrating a database from one dialect to another using sql-splitter.
MySQL to PostgreSQL
Section titled “MySQL to PostgreSQL”The most common migration path.
Step 1: Validate Source
Section titled “Step 1: Validate Source”sql-splitter validate prod_mysql.sql.gz --strict --progressStep 2: Analyze the Dump
Section titled “Step 2: Analyze the Dump”sql-splitter analyze prod_mysql.sql.gz --progressReview table sizes to estimate migration time.
Step 3: Convert
Section titled “Step 3: Convert”sql-splitter convert prod_mysql.sql.gz \ --to postgres \ -o prod_postgres.sql \ --progressStep 4: Validate Output
Section titled “Step 4: Validate Output”sql-splitter validate prod_postgres.sql \ --dialect=postgres \ --strict \ --progressStep 5: Import
Section titled “Step 5: Import”psql "$PG_CONN" < prod_postgres.sqlOr stream directly:
sql-splitter convert prod_mysql.sql.gz --to postgres -o - | psql "$PG_CONN"Handling Conversion Warnings
Section titled “Handling Conversion Warnings”Not all features convert perfectly. Common warnings:
ENUM Types
Section titled “ENUM Types”MySQL ENUMs don’t exist in PostgreSQL. Options:
- Convert to VARCHAR with CHECK constraint (automatic)
- Create custom TYPE (manual)
Auto-Increment
Section titled “Auto-Increment”Conversion is automatic:
- MySQL
AUTO_INCREMENT→ PostgreSQLSERIAL - PostgreSQL
SERIAL→ MySQLAUTO_INCREMENT
Session Commands
Section titled “Session Commands”MySQL-specific SET commands are stripped when converting to PostgreSQL.
MSSQL to MySQL
Section titled “MSSQL to MySQL”# Convertsql-splitter convert mssql_dump.sql \ --from mssql \ --to mysql \ -o mysql_dump.sql \ --progress
# Validatesql-splitter validate mysql_dump.sql --dialect=mysql --strictMSSQL-Specific Handling
Section titled “MSSQL-Specific Handling”GObatch separators are removedIDENTITY→AUTO_INCREMENTNVARCHAR→VARCHAR(with CHARACTER SET utf8mb4)DATETIME2→DATETIME
Best Practices
Section titled “Best Practices”- Always validate before and after - Catch issues early
- Use
--strictfor CI - Don’t ignore warnings - Test with a sample first - Convert a small sample before full dump
- Review warnings - Some may require manual fixes
Troubleshooting
Section titled “Troubleshooting””Unsupported feature” warnings
Section titled “”Unsupported feature” warnings”Use --strict to see all warnings, then address manually:
sql-splitter convert dump.sql --to postgres --strict 2>&1 | grep WARNINGEncoding issues
Section titled “Encoding issues”Ensure source dump is UTF-8:
file dump.sql# Should show: UTF-8 Unicode textLarge file performance
Section titled “Large file performance”For multi-GB dumps:
sql-splitter convert big.sql.gz --to postgres -o - | psql "$PG_CONN"This streams without writing an intermediate file.