Migrating from MySQL to PostgreSQL is one of the most common database tasks developers face. Maybe your project has grown and you need more advanced features. Maybe your new cloud hosting defaults to PostgreSQL. Or maybe you just want to future-proof your database.
Whatever the reason, this guide walks you through the entire migration process step by step — from exporting your MySQL database to importing it cleanly into PostgreSQL — with no data loss and no errors.
Why Migrate from MySQL to PostgreSQL?
Before we start, it helps to understand why developers make this switch.
The most common reasons are:
- PostgreSQL handles complex queries and large datasets better
- Better JSON support with the JSONB data type
- Stricter SQL standards make your queries more portable
- Most modern cloud platforms like Supabase, Railway, and Neon use PostgreSQL by default
- PostgreSQL supports advanced data types like arrays, ranges, and geographic data
- More powerful extension ecosystem including PostGIS for location data
If you are still deciding whether to switch, read our full PostgreSQL vs MySQL comparison first.
What You Need Before You Start
Before starting the migration, make sure you have the following ready:
- Access to your existing MySQL database
- A PostgreSQL database ready to receive the data
- Your MySQL login credentials (username, password, database name)
- About 15 to 30 minutes depending on your database size
Step 1 — Export Your MySQL Database
The first step is to export your MySQL database as a SQL dump file. This creates a single .sql file containing your entire database structure and data.
Using the command line:
Open your terminal and run this command:
mysqldump -u your_username -p your_database_name > my_database.sql
Replace your_username with your MySQL username and your_database_name with the name of your database. You will be asked to enter your password. After that, a file called my_database.sql will be created in your current folder.
Using phpMyAdmin:
If you use phpMyAdmin, go to your database, click the Export tab, choose SQL as the format, and click Go. This downloads the .sql file to your computer.
Using MySQL Workbench:
Go to Server → Data Export, select your database, choose Export to Self-Contained File, and click Start Export.
You now have a MySQL dump file. Keep it safe — this is your entire database.
Step 2 — Understand Why You Cannot Import It Directly
This is the part most people skip — and then wonder why they get 30 errors.
A MySQL dump file uses MySQL-specific syntax that PostgreSQL does not understand. Here are the most common problems:
AUTO_INCREMENT vs SERIAL
MySQL writes: id INT AUTO_INCREMENT PRIMARY KEY
PostgreSQL needs: id SERIAL PRIMARY KEY
Backticks vs Double Quotes
MySQL uses backticks around table and column names: SELECT * FROM \users``
PostgreSQL uses double quotes: SELECT * FROM "users"
TINYINT(1) vs BOOLEAN
MySQL stores true/false as TINYINT(1): is_active TINYINT(1) DEFAULT 0
PostgreSQL uses real booleans: is_active BOOLEAN DEFAULT FALSE
ENGINE=InnoDB
MySQL dump files contain lines like: ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
PostgreSQL does not understand this at all and will throw an error immediately.
DATETIME vs TIMESTAMP
MySQL uses DATETIME for date and time columns. PostgreSQL uses TIMESTAMP.
If you try to import your raw MySQL dump into PostgreSQL, every single one of these differences will cause an error. You would need to manually fix dozens or hundreds of lines in your SQL file — which is slow, tedious, and easy to get wrong.
Step 3 — Convert Your MySQL File to PostgreSQL Format
This is where DBConverter saves you hours of manual work.
Instead of editing your SQL file by hand, upload it to DBConverter and it automatically rewrites every syntax difference:
- AUTO_INCREMENT becomes SERIAL
- Backticks become double quotes
- TINYINT(1) becomes BOOLEAN
- ENGINE=InnoDB lines are removed cleanly
- DATETIME becomes TIMESTAMP
- All data types are mapped correctly
Here is how to use it:
- Go to https://dbconverter.site/sql-to-postgresql
- Click Upload File and select your MySQL .sql dump file
- The source format is detected automatically as MySQL
- Select PostgreSQL as the target format
- Click Convert
- Download your converted PostgreSQL file
The whole process takes under one minute even for large files up to 50 MB. The converted file is ready to import directly into PostgreSQL with no manual editing needed.
👉 Convert MySQL to PostgreSQL free: https://dbconverter.site/sql-to-postgresql
Step 4 — Create Your PostgreSQL Database
Before importing, you need a PostgreSQL database ready to receive your data.
Using the command line:
Log into PostgreSQL: psql -U postgres
Create a new database: CREATE DATABASE my_new_database;
Exit psql: \q
Using pgAdmin:
Right-click on Databases in the left panel, click Create → Database, enter your database name, and click Save.
Using a cloud platform:
If you are using Supabase, Railway, Neon, or any other cloud PostgreSQL provider, create a new database through their dashboard and copy the connection string. You will need it in the next step.
Step 5 — Import Your Converted File into PostgreSQL
Now import your converted PostgreSQL file into your new database.
Using the command line:
psql -U your_username -d your_database_name -f converted_file.sql
Replace your_username with your PostgreSQL username, your_database_name with your new database name, and converted_file.sql with the name of your converted file.
Using pgAdmin:
Open pgAdmin, right-click your database, select Query Tool, click the folder icon to open your converted SQL file, and press F5 to run it.
Using a cloud platform:
Most cloud PostgreSQL providers have a SQL editor in their dashboard. Open it, paste your converted SQL, and run it. Alternatively use the psql command line with your cloud connection string.
Step 6 — Verify Your Data
After importing, always verify that everything transferred correctly.
Check your tables exist:
In psql run: \dt
This lists all tables in your database. Compare this list with your original MySQL database to make sure nothing is missing.
Check your row counts:
Run this for each important table: SELECT COUNT(*) FROM your_table_name;
Compare the numbers with your MySQL database. They should match exactly.
Check a few rows of real data:
SELECT * FROM your_table_name LIMIT 10;
Look through the results and make sure the data looks correct — especially boolean columns, dates, and any JSON fields.
Test your application:
Connect your application to the new PostgreSQL database and run through the main features. Check for any query errors in your logs. Most common issues at this stage are queries that used MySQL-specific syntax that needs to be updated in your application code.
Step 7 — Update Your Application Connection String
The final step is pointing your application at the new PostgreSQL database.
A typical MySQL connection string looks like: mysql://username:password@localhost:3306/database_name
A PostgreSQL connection string looks like: postgresql://username:password@localhost:5432/database_name
Update your .env file or environment variables with the new PostgreSQL connection string. Restart your application and test again.
Common Errors During Migration and How to Fix Them
Even with a converted file, you might still run into a few issues. Here are the most common ones:
Error: syntax error at or near "unsigned" MySQL supports UNSIGNED integers but PostgreSQL does not. Replace INT UNSIGNED with INTEGER in your SQL file.
Error: column cannot be cast automatically to type boolean This happens when TINYINT(1) values contain numbers other than 0 and 1. Check your data and clean it before converting.
Error: invalid input syntax for type timestamp MySQL and PostgreSQL handle some date formats differently. Check any columns that store dates as strings instead of proper date types.
Error: relation already exists You are trying to import into a database that already has some of the tables. Either drop the existing tables first or create a fresh empty database.
Error: permission denied Your PostgreSQL user does not have enough permissions. Make sure your user has CREATE and INSERT privileges on the database.
Tips for a Smooth Migration
Always test on a copy first. Never migrate your production database directly. Export a copy, test the full migration process on a development server, and only then migrate production.
Do the migration during low traffic hours. If your application is live, schedule the migration when traffic is lowest to minimise downtime.
Keep your MySQL database running until you are confident. Do not delete your MySQL database immediately after migrating. Keep it as a backup for at least two weeks while you monitor your application on PostgreSQL.
Update your queries. After migrating the data, review your application code for any MySQL-specific queries. Things like using backticks in your SQL strings or relying on MySQL-specific functions will need to be updated.
Use connection pooling. PostgreSQL benefits greatly from connection pooling. Consider using PgBouncer or your cloud provider's built-in connection pooler for production deployments.
Frequently Asked Questions
How long does a MySQL to PostgreSQL migration take? For a small database under 50 MB, the entire process takes 15 to 30 minutes. For large databases over 1 GB, plan for a few hours including testing and verification.
Will I lose any data during migration? No, if you follow the steps correctly. The migration is a copy — your original MySQL database is not touched. Always verify row counts after importing.
Do I need to rewrite my application code? Sometimes. The database data migrates cleanly but if your application uses MySQL-specific SQL syntax in its queries — like backticks or MySQL functions — those will need to be updated to PostgreSQL syntax.
Can I migrate a live production database? Yes but you need to plan carefully. Export a snapshot, migrate it, test thoroughly, then switch your application connection string during a maintenance window. For zero-downtime migration you need a more advanced replication strategy.
Is DBConverter free to use? Yes, completely free. No account required, no usage limits, files are automatically deleted after two hours.
Conclusion
Migrating from MySQL to PostgreSQL is completely manageable when you follow the right steps. The biggest challenge is the syntax differences between the two databases — but with the right tool, that part is handled automatically in seconds.
To summarise the process:
- Export your MySQL database as a SQL dump file
- Convert it to PostgreSQL format using DBConverter
- Create a new PostgreSQL database
- Import the converted file
- Verify your data and update your application
The entire migration can be done in under 30 minutes for most databases. DBConverter handles all the syntax rewriting automatically so you can focus on testing your application rather than manually editing SQL files.
👉 Start your MySQL to PostgreSQL migration free: https://dbconverter.site/sql-to-postgresql
👉 Need to go the other way? Convert PostgreSQL to MySQL free: https://dbconverter.site/postgresql-to-sql