mysql 匯入中文亂碼解決一例

season0891發表於2014-08-20
檔案內容:
insert into tmp_xu set name="鄂爾1.中國";
insert into tmp_xu set name="藍1.中國";
insert into tmp_xu set name="1包.中國";
[root@I ~]# mysql -uroot -p -D x --default-character-set=gbk < hy-111.sql
Enter password:
[root@I ~]# mysql -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 172
Server version: 5.5.9-log MySQL Community Server (GPL)

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use x
Database changed
mysql> select * from tmp_xu;
+------+
| name |
+------+
|      |
|      |
| 1    |
+------+
3 rows in set (0.00 sec)

檔案中的中文不顯示

修改檔案內容:
set names gbk;
insert into tmp_xu set name="鄂爾1.中國";
insert into tmp_xu set name="藍1.中國";
insert into tmp_xu set name="1包.中國";

重新匯入:
mysql> select * from tmp_xu;
+------------+
| name       |
+------------+
|            |
|            |
| 1          |
| 鄂爾1.中國        |
| 藍1.中國        |
| 1包.中國        |
+------------+

中文顯示正常 。

完畢 。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/90618/viewspace-1254799/,如需轉載,請註明出處,否則將追究法律責任。

相關文章