日期:2014-05-16  浏览次数:20849 次

mysql UTF8编码
mysql> show table status like 'test';
+------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+-----------------+----------+----------------+---------+
| Name | Engine | Version | Row_format | Rows | Avg_row_length | Data_length | Max_data_length | Index_length | Data_free | Auto_increment | Create_time | Update_time | Check_time | Collation | Checksum | Create_options | Comment |
+------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+-----------------+----------+----------------+---------+
| test | MyISAM | 10 | Dynamic | 2 | 20 | 40 | 281474976710655 | 1024 | 0 | NULL | 2010-04-26 14:51:06 | 2010-04-26 14:59:56 | NULL | utf8_general_ci | NULL | | | 
+------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+-----------------+----------+----------------+---------+
1 row in set (0.00 sec)

mysql> set names utf8;
Query OK, 0 rows affected (0.00 sec)

mysql> select * from test;
+--------+
| name |
+--------+
| 澶╂触 | 
| 鍗椾含 | 
+--------+
2 rows in set (0.00 sec)

mysql> set names gbk;
Query OK, 0 rows affected (0.00 sec)

mysql> select * from test;
+------+
| name |
+------+
| 天津 | 
| 南京 | 
+------+
2 rows in set (0.00 sec)

mysql> 

为什么用UTF8查看时时乱码?GBK反而正常??

------解决方案--------------------
因为你的client的charset是gbk,connect的charset也是gbk,显示时与这两个charset都有关系。
很少有直接set names 'utf8'的。
------解决方案--------------------
探讨

我连接的时候指定字符集UTF8,
Server characterset: gbk
Db characterset: utf8
Client characterset: utf8
Conn. characterset: utf8
TCP port: 3306
查看也是乱码,表和库都是UTF8的,连接也是UTF8应该是正常的……

------解决方案--------------------
应该是你客户端根本没有装UTF8字符集,所以虽然你的CLIENT的ENCODING是UTF8,但是必须设置成GBK,才能显示一部分。 如果你的表中含有非GBK内容的话,我想你就明白了。
------解决方案--------------------
引用为什么用UTF8查看时时乱码?GBK反而正常??