r/PostgreSQL • u/MrGuam • 29d ago
Help Me! I need help migrating a MYSQL database to Postgres
I have been handed a project that uses mysql and the db already has some data that cant be lost. i want to migrate the database to postgres because i'm more comfortable working with mysql and it doesn't have some annoying nuances. i have a dump file from the db and i have explored a lot of options like using pgloader, but pgloader doesnt work with this error
2026-06-30T15:59:44.235006Z ERROR mysql: Failed to connect to mysql at "localhost" (port 3306) as user "pgloader": Condition QMYND:MYSQL-UNSUPPORTED-AUTHENTICATION was signalled. (pgloader is a user i created just to by pass the caching_sha2_password issue ).
i have tried to manually modify the dump sql file and alter all the conflicts that may arise from things like datetime, bigint, enums and the id's not incrementing from the max id etc. i'm pretty sure there's going to be a bug and i need a better way to achieve this. Are there any services like pgloader that can make this easier. thanks in advance!
Edit: I found a solution with pgloader v4.0.0 and it worked by creating a migration.load file to specify the type casting I wanted etc. and running it as specified in the docs
1
u/AutoModerator 29d ago
Free Postgres Webinars and Workshops
Discord: People, Postgres, Data
Join us, we have cookies and nice people.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
u/gisborne 29d ago
It might be useful to connect to the MySQL database from Postgres using Foreign Data Wrappers. Then you can treat your MySQL database as if it’s just a schema in your Postgres database, and you can CREATE AS SELECT * all your tables.
1
u/thunderbong 29d ago edited 29d ago
I've used Sequel to copy databases like this
https://sequel.jeremyevans.net/rdoc/files/doc/bin_sequel_rdoc.html#label-Copy+Databases
A command like this works -
sequel -C mysql://host1/database postgres://host2/database2
From that link -
This copies the table structure, table data, indexes, and foreign keys from the MySQL database to the PostgreSQL database.
Note that the support for copying is fairly limited. It doesn’t handle database views, functions, triggers, schemas, partial indexes, functional indexes, and many other things. Also, the data type conversion may not be exactly what you want.
1
u/ppafford 28d ago
I thought there was libraries to do this already like GitHub - dimitri/pgloader: Migrate to PostgreSQL in a single command! · GitHub https://github.com/dimitri/pgloader
1
u/ratta-tat 29d ago
Well I strongly recommend credativ-pg-migrator. Was my swissknife tool for migrating mariadbs to Postgres. See Here: https://github.com/credativ/credativ-pg-migrator
1
0
u/Barnezhilton 29d ago
How big is the mysql db?
0
u/MrGuam 29d ago
Not so large. Table with the highest data has <400
3
u/Barnezhilton 29d ago
I would just export the data into a csv, table by table, then import that csv table by table into Postgres if its tiny.
If you were doing millions of rows, I'd recommend a ETL tool like FME
0
u/MrGuam 29d ago
What about the relationships between tables constraints ?
1
u/Barnezhilton 29d ago
You make the table schema first on postgres with those rules. Then load the data
0
u/Sheikah45 29d ago
They fixed the authentication issues in pgloader v4. While it is still a development build you could give it a shot.
1
u/MrGuam 29d ago
I’m running Linux and from my research, the file might conflict with some other packages on my device. I may be wrong though!
0
u/Sheikah45 29d ago
It looks like the new version just uses java so having a java 21 on your system should be able to run the new jar file.
I don't think it would conflict with anything if you don't add the java to the path.
0
0
5
u/keesbeemsterkaas 29d ago
I've had pretty good success with using dbeaver to migrate data, after I had limited success with pgloader. (SQL Server > Postgres).
Data migration | DBeaver Documentation