2

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.

1

1 Answer 1

6

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'

Reference

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.