0
votes

I'm trying to load data from txt file to the following MySQL table

CREATE TABLE test_cyrillic
(
   id INT,
   name NATIONAL VARCHAR(200)
);

File with data looks like

1   Отзывы › Техника и оборудование

Database was created with UTF8 characterset and utf8_general_ci collation.

The command looks like

LOAD DATA LOCAL INFILE 'S:\\Projects\\MyDir\\test_cyrillic.txt'
 INTO TABLE test_cyrillic
 CHARACTER SET utf8
 FIELDS TERMINATED BY '\t'
 OPTIONALLY ENCLOSED BY '"' ESCAPED BY ''
 LINES TERMINATED BY '\r\n'

However, selecting data from this table I have the following output

id           name
0             B7K2K  :   "5E=8:0  8  >1>@C4>20=85

Whereas when inserting data through INSERT statement

insert into test_cyrillic values(2,N'Отзывы › Техника и оборудование')

everything is OK. Could anyone please tell me what is wrong about LOAD DATA in this case?

1

1 Answers

1
votes

I can't reproduce the problem.

File: test_cyrillic.txt:

1   Отзывы › Техника и оборудование

MySQL Command-Line:

mysql> SELECT VERSION();
+-----------------+
| VERSION()       |
+-----------------+
| 5.6.25          |
+-----------------+
1 row in set (0.00 sec)

mysql> CREATE DATABASE test CHARACTER SET 'utf8' COLLATE 'utf8_general_ci';
Query OK, 1 row affected (0.00 sec)

mysql> USE test;
Database changed

mysql> CREATE TABLE test_cyrillic (
    ->    id INT,
    ->    name VARCHAR(200) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci'
    -> );
Query OK, 0 rows affected (0.01 sec)

mysql> LOAD DATA INFILE '/path/to/file/test_cyrillic.txt'
    -> INTO TABLE test_cyrillic
    -> CHARACTER SET utf8
    -> FIELDS TERMINATED BY '\t'
    -> OPTIONALLY ENCLOSED BY '"' ESCAPED BY ''
    -> LINES TERMINATED BY '\r\n';
Query OK, 1 row affected (0.00 sec)
Records: 1  Deleted: 0  Skipped: 0  Warnings: 0

mysql> SELECT id, name FROM test_cyrillic;
+------+-------------------------------------------------------------+
| id   | name                                                        |
+------+-------------------------------------------------------------+
|    1 | Отзывы › Техника и оборудование                             |
+------+-------------------------------------------------------------+
1 row in set (0.00 sec)