๐Ÿš€ Jump straight to schema translation

Paste your MySQL CREATE TABLE statements and get PostgreSQL-ready SQL in seconds.

Translate MySQL โ†’ PostgreSQL Diff Two Schemas

Table of Contents

  1. Why Migrate from MySQL to PostgreSQL?
  2. Pre-Migration Checklist
  3. Step 1: Export MySQL Schema
  4. Step 2: Translate Schema to PostgreSQL
  5. Step 3: Migrate Your Data
  6. Step 4: Validate and Test
  7. Common Type Mapping Issues
  8. Migration Pitfalls to Avoid
  9. Frequently Asked Questions

Why Migrate from MySQL to PostgreSQL?

Teams typically migrate from MySQL to PostgreSQL for these reasons:

Pre-Migration Checklist

Step 1: Export MySQL Schema

Use mysqldump to export just the schema (no data) so you can review and translate it:

mysqldump --no-data --routines --events \
  -u username -p database_name > mysql_schema.sql
Include --routines and --events to capture stored procedures and events. You'll need to manually translate these since automated tools typically only handle CREATE TABLE.

Review the exported file for MySQL-specific syntax:

Step 2: Translate Schema to PostgreSQL

This is where most migrations get stuck. MySQL and PostgreSQL have different:

You have three options:

Option A: Automated Translation (Fastest)

Use the SQL Dialect Translator to convert your mysqldump output to PostgreSQL syntax. It handles type mapping, auto-increment conversion, and identifier quoting.

Option B: SchemaLens Diff (Recommended for Complex Schemas)

If you're redesigning the schema as part of migration, paste your MySQL schema and your target PostgreSQL schema into SchemaLens. It will show you exactly what's different and generate the migration SQL.

Option C: Manual Translation

For small schemas, you can manually rewrite the CREATE TABLE statements. Use the type mapping table below as a reference.

๐Ÿ› ๏ธ Save hours with automated translation

The SQL Dialect Translator converts MySQL schemas to PostgreSQL in seconds โ€” including type mapping, auto-increment syntax, and constraint adaptation.

Try the Translator โ†’

Step 3: Migrate Your Data

After translating the schema, create the tables in PostgreSQL and migrate the data.

Option 1: pgloader (Recommended)

pgloader is the gold standard for MySQL โ†’ PostgreSQL data migration. It handles type casting, index creation, and parallel loading.

pgloader mysql://user:pass@host/dbname postgresql://user:pass@host/dbname

Option 2: Custom ETL with Python

For complex transformations, use Python with SQLAlchemy and pandas:

import pandas as pd
from sqlalchemy import create_engine

mysql = create_engine('mysql+pymysql://user:pass@host/db')
postgres = create_engine('postgresql://user:pass@host/db')

df = pd.read_sql('SELECT * FROM users', mysql)
df.to_sql('users', postgres, if_exists='append', index=False)

Option 3: CSV Export/Import

For small datasets, export to CSV and use PostgreSQL's COPY command:

-- MySQL
SELECT * INTO OUTFILE '/tmp/users.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
FROM users;

-- PostgreSQL
COPY users FROM '/tmp/users.csv' CSV HEADER;
Watch out for encoding issues. MySQL's utf8mb4 maps to PostgreSQL's UTF8, but emoji and 4-byte characters can cause issues if not handled properly. Verify character set compatibility before migration.

Step 4: Validate and Test

Never skip validation. Here's a systematic approach:

Schema Validation

Data Validation

Use SchemaLens for Diff Validation

Export both schemas and diff them to catch anything you missed:

-- MySQL
mysqldump --no-data -u user -p mysql_db > mysql_schema.sql

-- PostgreSQL
pg_dump --schema-only -U user postgres_db > postgres_schema.sql

Then paste both into SchemaLens to see a visual diff of any remaining differences.

๐Ÿ” Catch schema differences before go-live

SchemaLens compares your MySQL and PostgreSQL schemas side-by-side and highlights any tables, columns, or indexes that didn't migrate correctly.

Compare Schemas Free โ†’

Common Type Mapping Issues

MySQL TypePostgreSQL TypeNotes
INT AUTO_INCREMENTSERIALUse BIGSERIAL for BIGINT
TINYINT(1)BOOLEANMySQL often uses this for booleans
VARCHAR(n)VARCHAR(n)No change needed
TEXTTEXTNo change needed
LONGTEXTTEXTPostgreSQL TEXT is unlimited
DATETIMETIMESTAMPOr TIMESTAMPTZ with timezone
JSONJSONBJSONB is faster and indexable
ENUMVARCHAR + CHECKPostgreSQL has no native ENUM in CREATE TABLE
SETTEXT or arrayNo direct equivalent
BLOBBYTEABinary data storage
FLOATREALOr DOUBLE PRECISION
DOUBLEDOUBLE PRECISIONNo change needed
DECIMAL(p,s)NUMERIC(p,s)No change needed
BITBOOLEANOr BIT if you need bit fields

Migration Pitfalls to Avoid

Frequently Asked Questions

How long does a MySQL to PostgreSQL migration take?

For schemas under 50 tables with a few GB of data, plan for 4-8 hours of focused work. Large schemas (500+ tables) or TB-scale data can take days or weeks. The schema translation is usually the fastest part; data migration and testing take the most time.

Can I migrate without downtime?

Yes, using a dual-write pattern: write to both MySQL and PostgreSQL during a transition period, then switch reads to PostgreSQL once validated. Tools like Debezium can help with CDC (Change Data Capture).

What about stored procedures and triggers?

These must be manually rewritten. MySQL uses SQL/PSM syntax while PostgreSQL uses PL/pgSQL. The logic is often similar but function names and conventions differ.

Is pgloader free?

Yes, pgloader is open-source and free. It's the most popular tool for MySQL โ†’ PostgreSQL data migration and handles most edge cases automatically.

Do I need to change my application code?

Probably. Even with ORMs like Prisma or SQLAlchemy, you may need to update connection strings, query syntax, and handling of specific data types. Test thoroughly in a staging environment.

Ready to migrate? Start with your schema.

Convert your MySQL CREATE TABLE statements to PostgreSQL syntax in seconds, then diff the result to catch anything the translator missed.

Translate Schema โ†’ Diff & Validate โ†’