Trace:Incorrect string value: '\xAD\xBF The...' for column ...

1. 应用程序报错
485333 2011-09-19 04:05:41,597 ERROR [main]  com.csf.cdp.dealComparison.dao.DBDao     - SaveTraceData Error:Incorrect
string value: '\xAD\xBF The...' for column 'data_trace' at row 1
485333 2011-09-19 04:05:41,597 ERROR [main]  com.csf.cdp.dealComparison.dao.DBDao     - SaveTraceData Error:Incorrect
string value: '\xAD\xBF The...' for column 'data_trace' at row 1
485335 2011-09-19 04:05:41,599 ERROR [main] com.csf.cdp.dealComparison.CompareDealer     - Error While Dealing
Trace:Incorrect string value: '\xAD\xBF The...' for column 'data_trace' at row 1
百度、google了很多资料,itpub、csdn等论坛发了帖子,绝大部分朋友一致认为是字符集的问题,其中一个版主狼哥说“\xAD\xBF The”就是汉字“倍”。
决定去check下字符集。
2 查看mysql原始字符集
mysql> show variables like 'collation_%';
+----------------------+-------------------+
| Variable_name        | Value             |
+----------------------+-------------------+
| collation_connection | utf8_general_ci   |
| collation_database   | latin1_swedish_ci |
| collation_server     | latin1_swedish_ci |
+----------------------+-------------------+
3 rows in set (0.05 sec)
mysql> show variables like 'character_set_%';
+--------------------------+----------------------------------+
| Variable_name            | Value                            |
+--------------------------+----------------------------------+
| character_set_client     | utf8                             |
| character_set_connection | utf8                             |
| character_set_database   | latin1                           |
| character_set_filesystem | binary                           |
| character_set_results    | utf8                             |
| character_set_server     | latin1                           |
| character_set_system     | utf8                             |
| character_sets_dir       | /usr/local/mysql/share/charsets/ |
+--------------------------+----------------------------------+
8 rows in set (0.02 sec)
mysql>

3. 修改my.cnf
vi /etc/my.cnf
在[client]下添加
default-character-set=utf8
在[mysqld]下添加
default-character-set=utf8
但是5.5.8版本的时候这样设置会报
[ERROR] /usr/local/mysql/bin/mysqld: unknown variable 'default-character-set=utf8'的错误。
查看了文档,character_set_server 支持配置文件变量设置
在[client]下添加
default-character-set=utf8
在[mysqld]下添加
default-character-set=utf8
[root@ldap-mysql-svn-trac data]# service mysqld start
Starting MySQL...                                          [  OK  ]
[root@ldap-mysql-svn-trac data]#
[root@ldap-mysql-svn-trac data]# mysql -uroot -pmysql
mysql: unknown variable 'character_set_server=utf8'
[root@ldap-mysql-svn-trac data]#
竟然登录不进去,报不识别'character_set_server=utf8'的错误。
继续修改/etc/my.cnf文件,service能正常启动,但是mysql登录不进去,可能是[client]下的问题,进去注释掉
在[client]下注释
[root@ldap-mysql-svn-trac data]# vim /etc/my.cnf
# default-character-set=utf8

4.重新启动MySQL
[root@ldap-mysql-svn-trac data]# service mysqld restart
Shutting down MySQL.                                       [  OK  ]
Starting MySQL....                                         [  OK  ]
5.查看字符集设置
[root@ldap-mysql-svn-trac data]# mysql -uroot -pmysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.10-log Source distribution
Copyright (c) 2000, 2010, 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> show variables like 'collation_%';
+----------------------+-----------------+
| Variable_name        | Value           |
+----------------------+-----------------+
| collation_connection | utf8_general_ci |
| collation_database   | utf8_general_ci |
| collation_server     | utf8_general_ci |
+----------------------+-----------------+
3 rows in set (0.05 sec)
mysql> show variables like 'character_set_%';
+--------------------------+----------------------------------+
| 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/charsets/ |
+--------------------------+----------------------------------+
8 rows in set (0.01 sec)
mysql>

你可能感兴趣的:(Trace:Incorrect string value: '\xAD\xBF The...' for column ...)