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反而正常??
+------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+-----------------+----------+----------------+---------+
| 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反而正常??
Db characterset: utf8
Client characterset: gbk
Conn. characterset: gbk
很少有直接set names 'utf8'的。
Server characterset: gbk
Db characterset: utf8
Client characterset: utf8
Conn. characterset: utf8
TCP port: 3306
查看也是乱码,表和库都是UTF8的,连接也是UTF8应该是正常的啊 ,为什么会是乱码呢
好,终于引到正题了,你的显示终端是用的encoding utf8吗?我猜你肯定用的是encoding gbk吧。
如果你想utf8下正常显示,设置一下encoding utf8吧,(terminal下)
据我所知,ubuntu下的terminal缺省是utf8。
数据库没有错,只跟显示终端有关系。
这个是因为你的DOS不支持UTF8,所以当MYSQL以UTF8返回结果时,DOS无法正常显示,但当你set names gbk 后,MYSQL会把表的字符转换成GBK,而GBK是DOS可以正常显示的字符集。