2014-01-20 140 views
2

我想導入一些中文字符到MySQL數據庫中。但是其中一些內容被省略,有些則顯示爲無意義的。如下所示的圖片:csv從unicode導入到utf8 phpmyadmin

什麼是在數據庫:

enter image description here

是什麼在Excel文件:

enter image description here

謝謝!

你好,這裏是addtional信息:

文本文檔

巴掌 bāzhang (a slap of the) palm  打 beat human activities 
巴掌 bāzhang (a slap of the) palm  搧 spank human activities 
巴掌 bāzhang (a slap of the) palm  揍 hit human activities 
把 bá tools and objects with a handle 掃帚 broom tools 
把 bá tools and objects with a handle 鎖 lock man-made 

顯示創建表

CREATE TABLE `table 1` (
`CL_in_Character` varchar(10) CHARACTER SET utf8 DEFAULT NULL, 
`CL_in_Pinyin` varchar(14) CHARACTER SET utf8 DEFAULT NULL, 
`Definition_in_Dictionary` varchar(74) CHARACTER SET utf8 DEFAULT NULL, 
`Associated_nouns_in_Chinese` varchar(16) CHARACTER SET utf8 DEFAULT NULL, 
`Associated_nouns_in_English` varchar(38) CHARACTER SET utf8 DEFAULT NULL, 
`Associated_noun_categories` varchar(38) CHARACTER SET utf8 DEFAULT NULL 
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci 
+0

顯示錶格的定義。執行'SHOW CREATE TABLE '並在您的問題中發佈結果。還以文本形式(不是圖像)發佈幾行文件。 – peterm

+0

您好,請參閱我的版本。謝謝! – Soya

+0

您的文件是否被讀取並插入爲utf8? phpMyAdmin是否顯示在utf8中?如果你在MySQL中插入一箇中文字符,它可以正確顯示嗎? –

回答

2

我不能告訴打開的文檔格式和phpMyAdmin的,但你可以成功導入數據,格式爲CSV,格式爲:

LOAD DATA INFILE '/path/to/your/file.csv' INTO TABLE `table 1` 
CHARACTER SET 'utf8' 
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' 
LINES TERMINATED BY '\n' 
IGNORE 1 LINES 

通過正確格式爲CSV我的意思是

 
CL_in_Character,CL_in_Pinyin,Definition_in_Dictionary,Associated_nouns_in_Chinese,Associated_nouns_in_English,Associated_noun_categories 
"巴掌","bāzhang","(a slap of the) palm","打","beat","human activities" 
"巴掌","bāzhang","(a slap of the) palm","搧","spank","human activities" 
"巴掌","bāzhang","(a slap of the) palm","揍","hit","human activities" 
"把","bá","tools and objects with a handle","掃帚","broom","tools" 
"把","bá","tools and objects with a handle","鎖","lock","man-made" 

讓我們試一下

 
mysql> CREATE TABLE `table 1` (
    -> `CL_in_Character` varchar(10) CHARACTER SET utf8 DEFAULT NULL, 
    -> `CL_in_Pinyin` varchar(14) CHARACTER SET utf8 DEFAULT NULL, 
    -> `Definition_in_Dictionary` varchar(74) CHARACTER SET utf8 DEFAULT NULL, 
    -> `Associated_nouns_in_Chinese` varchar(16) CHARACTER SET utf8 DEFAULT NULL, 
    -> `Associated_nouns_in_English` varchar(38) CHARACTER SET utf8 DEFAULT NULL, 
    -> `Associated_noun_categories` varchar(38) CHARACTER SET utf8 DEFAULT NULL 
    -> ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; 
Query OK, 0 rows affected (0.03 sec) 

mysql> LOAD DATA INFILE '/tmp/utf.csv' INTO TABLE `table 1` 
    -> CHARACTER SET 'utf8' 
    -> FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' 
    -> LINES TERMINATED BY '\n' 
    -> IGNORE 1 LINES; 
Query OK, 5 rows affected (0.00 sec) 
Records: 5 Deleted: 0 Skipped: 0 Warnings: 0 

mysql> select * from `table 1`; 
+-----------------+--------------+---------------------------------+-----------------------------+-----------------------------+----------------------------+ 
| CL_in_Character | CL_in_Pinyin | Definition_in_Dictionary  | Associated_nouns_in_Chinese | Associated_nouns_in_English | Associated_noun_categories | 
+-----------------+--------------+---------------------------------+-----------------------------+-----------------------------+----------------------------+ 
| 巴掌   | bāzhang  | (a slap of the) palm   | 打       | beat      | human activities   | 
| 巴掌   | bāzhang  | (a slap of the) palm   | 搧       | spank      | human activities   | 
| 巴掌   | bāzhang  | (a slap of the) palm   | 揍       | hit       | human activities   | 
| 把    | bá   | tools and objects with a handle | 掃帚      | broom      | tools      | 
| 把    | bá   | tools and objects with a handle | 鎖       | lock      | man-made     | 
+-----------------+--------------+---------------------------------+-----------------------------+-----------------------------+----------------------------+ 
5 rows in set (0.00 sec) 
+0

它確實幫了我。只有一件事:LINES終止於'\ n',應該與'\ r \ n'換行符一起使用(在使用odf的情況下) – Jeffz

0

我剛剛有同樣的問題,因爲你並達成了這個問題。然後,我通過改變在phpMyAdmin選項解決它從

Lines terminated with: auto 

Lines terminated with: \n 
0

我解決了這個複製整個Excel數據,並粘貼爲值,那麼它將識別的字符。