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

mysql乱码的问题(数据库编码显示一致的)
我遇到的乱码问题:
当前数据库编码utf8:
mysql> show variables like 'char%';
+--------------------------+----------------------------------------+
| Variable_name | Value |
+--------------------------+----------------------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/local/mysql/share/mysql/charsets/ |
+--------------------------+----------------------------------------+
8 rows in set (0.00 sec)
数据表结构:
mysql> show create table tvehicle;
| Table | Create Table  
| tvehicle | CREATE TABLE `tvehicle` (
  `uid` bigint(21) unsigned DEFAULT '0' COMMENT '用户id',
  `gitude_s` float(8,5) DEFAULT NULL COMMENT '经度',
  `itude_s` float(8,5) DEFAULT NULL COMMENT '纬度',
  `speed` smallint(5) DEFAULT NULL COMMENT '当前速度',
  `telnum` smallint(5) DEFAULT NULL COMMENT '区号',
  `province` char(32) DEFAULT NULL,
  `city` char(32) DEFAULT NULL,
  `district` char(32) DEFAULT NULL,
  `districtcode` int(11) DEFAULT NULL,
  `lt_time` int(11) unsigned DEFAULT '0',
  `update_time` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`eqid`),
  KEY `telnum` (`telnum`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='信息表' |
+------------------+---------------------------------------
问题来了,我查询记录,发现乱码:
mysql> select * from tvehicle limit 1;
Current database: data
+------------------+------------+-----------+----------+-------------+------------+-------+--------+----------
| uid | longitude_s | latitude_s | speed | telnum | province | city | district | districtcode | lt_time | update_time | create_time |
+------------------+------------+-----------+----------+-------------+------------+-------+--------+----------
| 10000170 | 111.54987 | 23.80696 | 0 | 574 | æµ?æ±?ç?? | NULL | é??å·?å?º | 330212 | 1346888867 | 2010-09-06 08:55:48 | 2010-05-06 18:07:20 |
+------------------+------------+-----------+----------+-------------+------------+-------+--------+----------
1 row in set (0.01 sec)

我做以下操作就可以显示正常了: