我试图将数据从txt文件加载到以下MySQL表
CREATE TABLE test_cyrillic
(
id INT,
name NATIONAL VARCHAR(200)
);
带有数据的文件看起来像
1 Отзывы › Техника и оборудование
数据库是使用UTF8 characterset和utf8_general_ci整理创建的。
该命令看起来像
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'
但是,从此表中选择数据我有以下输出
id name
0 B7K2K : "5E=8:0 8 >1>@C4>20=85
而通过INSERT语句插入数据
insert into test_cyrillic values(2,N'Отзывы › Техника и оборудование')
一切都好。
在这种情况下,有人可以告诉我LOAD DATA有什么问题吗?
答案 0 :(得分:1)
我无法重现这个问题。
档案:test_cyrillic.txt
:
1 Отзывы › Техника и оборудование
MySQL命令行:
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)