0

I would like import a SQL file encoded into Latin1. I would like keep this file encoding. Data into sql file are well encoded into Latin1.

I executed this command :

mysql -hlocalhost -uroot -p Database --default-character-set=latin1 < file.sql

But data are encoded into utf8 encoded into Database. I don't understand why data are converted. I should obtain "é" (Latin1)and I obtain "é" (utf8).

I created my Database with :

CREATE DATABASE Database CHARACTER SET latin1 COLLATE latin1_swedish_ci;

Can you help me please, how I can import my SQL file to keep enconding ?

0

2 Answers 2

4

The database charset may be overridden by the table charset. The table charset may be overridden by the column charset. Please provide SHOW CREATE TABLE.

What encoding are the bytes in file.sql? If the character é takes one byte (hex E9), then it is encoded latin1. If it takes two bytes (hex C3A9), then it is utf8. If C3A9 is interpreted as latin, it comes out asé`. This is called Mojibake.

By saying --default-character-set=latin1, you are announcing that the bytes in the source are encoded latin1.

Even if the source bytes are latin1 (eg hex 96), the column in the table can be CHARACTER SET utf8. The encoding will be converted (to C3A9) as the insertion is performed.

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

Comments

1
mysql -u your-username -p your-password --database your-db --default-character-set utf8mb4 < my_data.sql

worked.

Encoding is still hell on earth, don't get why MySql/Maria are still not defaulted to UTF-8 and even ignoring the file's import format.

1 Comment

MySQL 8.0 defaults to utf8mb4. This has led to a significant decline on charset questions in this forum. Unfortunately, there are still datasets outside MySQL that are in other encodings.

Your Answer

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