无法将 utf16 编码的文件导入 mysql [英] failed to import utf16 encoded file into mysql
问题描述
我有 txt 管道分隔文件(非英语 - 下面给出的是波兰语,但也涉及其他语言),编码为 utf16,例如:
<前>头1|头2|头3|头4brytyjski wytwórca|z jakże bogatą|przedwojenną historią|zapowiedział wypuszczeniedziś znamy|jedynie Paletę kolorów|obejmującą aż|jedną pozycję我尝试了很多不同的方法将其放入 mysql 表中:
逐行使用 php
以我能想到的任何方式通过控制台使用 LOAD DATA INFILE,例如:
我总是得到:
乱码(错误编码)条目
什么都没有输入(sql写入默认值)
顺便提一下:我还设置了 utf8、utf16、latin2(用于东欧编码)......和 nada 的表格.
顺便说一句:当我更改 encoding 时,例如在记事本中我可以导入 utf8 - 没问题,但是如果我有需要 utf16(亚洲)的字符,或者我想自动输入文件怎么办?
Php iconv 等似乎不能胜任这项工作.
任何帮助,一些阅读的链接等将不胜感激,因为我刚刚没有想法.
注意
无法加载使用 ucs2
、utf16
或 utf32
字符集的数据文件.
UTF-8 可以表示与 UTF-16 相同的全套 Unicode 代码点.也许仅使用该编码最简单(或在导入其他语言之前对文件进行转码,例如通过 PHP 的 iconv()
函数)?
I have txt pipe-delimited file (non-english - given below is Polish, but other langs are also involved), encoded utf16, something like:
head1|head2|head3|head4 brytyjski wytwórca|z jakże bogatą|przedwojenną historią|zapowiedział wypuszczenie dziś znamy|jedynie paletę kolorów|obejmującą aż|jedną pozycję
I tried lots of different ways to get it into mysql table:
line-by-line using php
using LOAD DATA INFILE via console in any way I could conceive, e.g.:
LOAD DATA INFILE 'C:/\wamp/\www/\hmvc/\prop_tst.txt' INTO TABLE hmvc.table CHARACTER SET 'utf8' FIELDS TERMINATED BY '|' LINES TERMINATED BY '\n' \g
I always get either:
garbled (wrongly encoded) entries
nothing gets entered (sql writes default values)
Just to mention: I also set table in utf8, utf16, latin2 (for Eastern European encoding) ... and nada.
BTW: When I change encoding , e.g. in Notepad to utf8 I can import - no problem, but what if I have chars requiring utf16 (Asian), or I want to automate file input?
Php iconv etc. seems not to be up to the job.
Any help, link to some reading etc. would be much appreciated, as I am freshly out of ideas.
As documented under LOAD DATA INFILE
Syntax:
Note
It is not possible to load data files that use the
ucs2
,utf16
, orutf32
character set.
UTF-8 can represent the same full set of Unicode codepoints as UTF-16. Perhaps it'd be easiest to use only that encoding (or transcode the file prior to import in some other language, such as via PHP's iconv()
function)?
这篇关于无法将 utf16 编码的文件导入 mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!