Skip to content

Database Migration

This guide walks through migrating a database from one dialect to another using sql-splitter.

The most common migration path.

Terminal window
sql-splitter validate prod_mysql.sql.gz --strict --progress
Terminal window
sql-splitter analyze prod_mysql.sql.gz --progress

Review table sizes to estimate migration time.

Terminal window
sql-splitter convert prod_mysql.sql.gz \
--to postgres \
-o prod_postgres.sql \
--progress
Terminal window
sql-splitter validate prod_postgres.sql \
--dialect=postgres \
--strict \
--progress
Terminal window
psql "$PG_CONN" < prod_postgres.sql

Or stream directly:

Terminal window
sql-splitter convert prod_mysql.sql.gz --to postgres -o - | psql "$PG_CONN"

Not all features convert perfectly. Common warnings:

MySQL ENUMs don’t exist in PostgreSQL. Options:

  1. Convert to VARCHAR with CHECK constraint (automatic)
  2. Create custom TYPE (manual)

Conversion is automatic:

  • MySQL AUTO_INCREMENT → PostgreSQL SERIAL
  • PostgreSQL SERIAL → MySQL AUTO_INCREMENT

MySQL-specific SET commands are stripped when converting to PostgreSQL.

Terminal window
# Convert
sql-splitter convert mssql_dump.sql \
--from mssql \
--to mysql \
-o mysql_dump.sql \
--progress
# Validate
sql-splitter validate mysql_dump.sql --dialect=mysql --strict
  • GO batch separators are removed
  • IDENTITYAUTO_INCREMENT
  • NVARCHARVARCHAR (with CHARACTER SET utf8mb4)
  • DATETIME2DATETIME
  1. Always validate before and after - Catch issues early
  2. Use --strict for CI - Don’t ignore warnings
  3. Test with a sample first - Convert a small sample before full dump
  4. Review warnings - Some may require manual fixes

Use --strict to see all warnings, then address manually:

Terminal window
sql-splitter convert dump.sql --to postgres --strict 2>&1 | grep WARNING

Ensure source dump is UTF-8:

Terminal window
file dump.sql
# Should show: UTF-8 Unicode text

For multi-GB dumps:

Terminal window
sql-splitter convert big.sql.gz --to postgres -o - | psql "$PG_CONN"

This streams without writing an intermediate file.