What is the easiest way to export data from mysql and import it in postgresql?
I am having trouble with the MySQL binary fields conversion.
What is the easiest way to export data from mysql and import it in postgresql?
I am having trouble with the MySQL binary fields conversion.
The equivalent of binary type in MySQL is bytea in PostgreSQL.
You can use pgloader (simplest way)
After installing pgloader, create simple script test.load
load database
from mysql://username:password@host/database_name
into postgresql://postgres:postgres@localhost/database_name
WITH include drop, create tables, create indexes, reset sequences
SET maintenance_work_mem to '128MB',
work_mem to '12MB'
CAST type binary TO bytea drop typemod using byte-vector-to-bytea;
Run it in your terminal:
pgloader test.load
Another way is using mysqldump
1. Dump it with hex-blob option
mysqldump -u username -p -h host --skip-quote-names --hex-blob --skip-triggers \
--compact --no-create-info your_db your_table > prepg.dump
2. Do sed so it can be inserted to you bytea type column
sed "s/0x\([0-9A-F]*\)/decode('\1','hex')/g" prepg.dump > pg.dump
3. Load into your PostgreSQL table
\i '/path_to_file/pg.dump'