1

My file dump.sql for MySQL

MySQL dump 10.13  Distrib 5.7.20, for Win64 (x86_64)

in file set encoding cp1251
Error in the normal recovery psql databasename < /path/to/dump/dump.sql:

ERROR:  invalid byte sequence for encoding "UTF8": 0xd3 0xc0

I need to convert it so that it can be restored in postgresql.
Are there any plugins? or ways?

2
  • The error is pretty clear. You tried to read the script file as UTF8 when you say you saved it as CP1251. Save it as UTF8. Commented Jan 30, 2018 at 13:01
  • Dumps aren't backups, they are SQL scripts. You aren't recovering anything, you are executing a script. If you use the wrong codepage you may end up with garbled text. You can still run into trouble if the script contains syntax that isn't valid for Postgres. Commented Jan 30, 2018 at 13:03

1 Answer 1

3

You can tell psql what the encoding of the SQL script is:

PGCLIENTENCODING=WIN1251 psql -d databasename -f /path/to/dump/dump.sql
Sign up to request clarification or add additional context in comments.

2 Comments

thanks. but now psql:/home/path/to/dump/dump.sql:7988: ERROR: syntax error at or near "`"
I cannot possibly fix all the syntax differences between MySQL and PostgreSQL in comments. But it seems like your encoding problem is solved, right? Did you try mysqldump --compatible=postgresql?

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.