征集MySQL 乱码现象
想整理一篇中文乱码的贴子。希望能从各位得到一些对各种乱码症状的补充。比如 mysql windows中DOS下中文乱码,php中GBK显示乱码等现象。
http://blog.csdn.net/ACMAIN_CHM/archive/2009/05/12/4174186.aspx
提供症状即可,如同时有解决方法更佳。
------解决方案--------------------学习一下..其实我觉得MySQL的乱码问题来来去去也是那么两三个原因..
------解决方案--------------------可以看看我提供的 mysql 命令行下 显示 中文字符 问题:http://topic.csdn.net/u/20090512/16/1f8c65cf-e2fc-4a9f-b95e-950de5871dde.html
Mysql 默认字符设置为 gbk
在Mysql query browser 可以正确 显示 中文。但是命令行下:
mysql> status
--------------
C:\Program Files\MySQL\MySQL Server 5.1\bin\mysql.exe Ver 14.14 Distrib 5.1.30,
for Win32 (ia32)
Connection id: 1
Current database: test
Current user: root@localhost
SSL: Not in use
Using delimiter: ;
Server version: 5.1.30-community MySQL Community Server (GPL)
Protocol version: 10
Connection: localhost via TCP/IP
Server characterset: gbk
Db characterset: gbk
Client characterset: gbk
Conn. characterset: gbk
TCP port: 3306
Uptime: 22 min 39 sec
Threads: 1 Questions: 6 Slow queries: 0 Opens: 15 Flush tables: 1 Open tabl
es: 8 Queries per second avg: 0.4
--------------
mysql> select * from Course;
+-----+--------------+------+---------+
| Cno | Cname | Cpno | Ccredit |
+-----+--------------+------+---------+
| 1 | | 7 | 4 |
| 2 | | NULL | 2 |
| 3 | | 1 | 4 |
| 4 | | 6 | 3 |
| 5 | | 7 | 4 |
| 6 | Java | NULL | 2 |
| 7 | | 6 | 4 |
+-----+--------------+------+---------+
7 rows in set (0.55 sec)
不能 显示 中文。正确的应该为:
Cno | Cname | Cpno | Ccredit |
+-----+--------------+------+---------+
| 1 | 数据库系统 | 5 | 4 |
| 2 | 高等数续 | NULL | 2 |
| 3 | 信息系统 | 1 | 4 |
| 4 | 操作系统 | 6 | 3 |
| 5 | 数据结构 | 7 | 4 |
| 6 | Java程序设计 | NULL | 2 |
| 7 | 编译原理 | 6 | 4 |
mysql> show full columns from Course;
+---------+--------------+----------------+------+-----+---------+-------+------
---------------------------+---------+
| Field | Type | Collation | Null | Key | Default | Extra | Privi
leges | Comment |
+---------+--------------+----------------+------+-----+---------+-------+------
---------------------------+---------+
| Cno | varchar(10) | gbk_chinese_ci | NO | PRI | NULL | | selec
t,insert,update,references | |
| Cname | varchar(50) | gbk_chinese_ci | YES | | NULL | | selec
t,insert,update,references | |
| Cpno | varchar(10) | gbk_chinese_ci | YES | MUL | NULL | | selec
t,insert,update,references | |
| Ccredit | smallint(10) | NULL | YES | | NULL | | selec
t,insert,update,references | |
+---------+--------------+----------------+------+-----+---------+-------+------
---------------------------+---------+
mysql> set names 'latin1';
mysql> select * from Course;
+-----+----------+------+---------+
| Cno | Cname | Cpno | Ccredit |
+-----+------