Skip to content
migration.tools
MySQL to PostgreSQL

MySQL to PostgreSQL converter

Convert a mysqldump or phpMyAdmin export into SQL that PostgreSQL will run: schema, indexes, foreign keys and the INSERT data. Paste the dump, get a script you can pipe into psql.

Going the other way? PostgreSQL to MySQL

Options

MySQL SQL

PostgreSQL SQL

The result appears here as soon as there is input.

Processed on this device. Nothing you paste or drop is uploaded.

How to use it

  1. 1Export your database (mysqldump or phpMyAdmin) and paste the SQL, or drop the .sql file.
  2. 2Read the review notes under the output — they list everything that needs a human decision.
  3. 3Download the PostgreSQL script and run it against a staging database first.

What changes between MySQL and PostgreSQL

Backtick identifiers become double-quoted identifiers, and MySQL's backslash string escapes (\', \n) are rewritten as standard SQL strings.

AUTO_INCREMENT columns become GENERATED BY DEFAULT AS IDENTITY, so explicit ids from your dump still insert. A setval() call for each table is appended to move the sequence past the highest imported id — the step people most often forget.

TINYINT(1) becomes BOOLEAN and the 0/1 values in INSERTs become FALSE/TRUE. UNSIGNED integers are widened one size so they can't overflow. DATETIME becomes TIMESTAMP, LONGTEXT becomes TEXT, BLOBs become BYTEA and JSON becomes JSONB.

ENUM columns become VARCHAR with a CHECK constraint listing the allowed values. Inline KEY definitions are split out into CREATE INDEX statements with table-prefixed names, because PostgreSQL index names are unique per schema, not per table.

Zero dates ('0000-00-00') are replaced with NULL, and ENGINE, CHARSET, COLLATE, LOCK TABLES and /*! … */ directives are dropped.

What to check before you run it

Run the converted script against an empty staging database first, inside a transaction if the target supports transactional DDL. The review notes under the output list every statement that was dropped, every type with no direct equivalent and every clause that needs a manual decision.

Views, triggers, stored procedures and functions are passed through unchanged and flagged. Their bodies are written in MySQL's procedural language and need a human rewrite for PostgreSQL.

After loading, compare row counts table by table. For a deeper check, export a table from both databases and run the two files through the CSV compare tool.

Questions

Does it convert the data, or only the schema?

Both. INSERT statements are rewritten with PostgreSQL quoting, boolean values and NULL-for-zero-dates. Turn off “Include INSERT data” if you only want the schema.

What about ON UPDATE CURRENT_TIMESTAMP?

PostgreSQL has no column-level equivalent. The clause is removed and listed in the review notes so you can add a trigger or set the timestamp in application code.

How large a dump can I convert?

Dumps of tens of megabytes convert in a few seconds in a modern browser. For multi-gigabyte databases use a streaming tool such as pgloader for the data, and this converter for the schema.

Guides that use this tool