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 (output goes to stdout when -o is omitted):

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

Not all features convert perfectly. Common warnings:

MySQL ENUMs don’t exist in PostgreSQL. Options:

  1. Convert to VARCHAR(255) (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
  • IDENTITY(1,1)AUTO_INCREMENT
  • NVARCHARVARCHAR (the output header sets SET NAMES utf8mb4)
  • DATETIME2DATETIME(6)
  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

Warnings are printed to stderr by default; use --json to inspect them, then address manually:

Terminal window
sql-splitter convert dump.sql --to postgres -o pg.sql --json | jq '.warnings'

Add --strict to fail the conversion when any warnings are generated.

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 | psql "$PG_CONN"

This streams without writing an intermediate file.