我在处理Utf8时遇到了问题。我已经修改了数据库和表,如下所示:
mysql>alter database database_name character set Utf8 collate utf8_unicode_ci;
mysql>alter table table_name character set Utf8 collate utf8_unicode_ci;当我检查它的变量以显示字符配置和排序规则配置时,它显示如下:
mysql> show variables like '%character%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | latin1 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
mysql> show variables like '%collation%';
+----------------------+-------------------+
| Variable_name | Value |
+----------------------+-------------------+
| collation_connection | latin1_swedish_ci |
| collation_database | utf8_unicode_ci |
| collation_server | latin1_swedish_ci |
+----------------------+-------------------+
3 rows in set (0.00 sec)当我将/etc/my.cnf设置为如下所示时,它工作得很好:
[mysqld]
character-set-server=utf8
[mysql]
default-character-set=utf8仅供参考,以下是JavaScript上Utf8编码的代码:
var Utf8 = {
encode : function (string) {
string = string.replace(/\r\n/g,"\n");
var utftext = "";
deleteCookie('unicodeLength');
for (var n = 0; n < string.length; n++) {
var c = string.charCodeAt(n);
if (c < 128) {
utftext += String.fromCharCode(c);
}
else if((c > 127) && (c < 2048)) {
utftext += String.fromCharCode((c >> 6) | 192);
utftext += String.fromCharCode((c & 63) | 128);
}
else {
utftext += String.fromCharCode((c >> 12) | 224);
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
utftext += String.fromCharCode((c & 63) | 128);
}
}
return utftext;
}
};当从/etc/my.cnf中删除这两行代码时,问题就出现了。有什么建议吗?
发布于 2013-05-30 16:15:46
我认为你应该在你的/etc/my.cnf文件中添加skip-character-set-client-握手。
这是我的。
[mysqld]
default-character-set=utf8
character-set-server=utf8
skip-character-set-client-handshake
collation-server=utf8_unicode_ci
init-connect='SET NAMES utf8'
init_connect='SET collation_connection = utf8_general_ci'
port = 3306https://stackoverflow.com/questions/14432299
复制相似问题