问题:ERROR 1366 (HY000): Incorrect string value: 'xC4xEAxBCxB6' for column 'xxx' at row 1 在DOS中插入或查询中文出现乱码
登入mysql,输入命令:show variables like '%char%';
得到: +--------------------------+--------------------------+ | 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 utf8 | character_set_system utf8 | character_sets_dir G:mysqlsharecharsets +--------------------------+--------------------------+
如果出现上述情况就需要更改数据库编码:alter database 数据库名 charset utf8;
再用命令: 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 G:mysqlsharecharsets +--------------------------+--------------------------+
虽然编码已经一致,但是输入中文任然会报错
此时需要输入命令:set character_set_client = gbk; 设置插入时接收的编码为GBK, 这样就可以插入中文
set character_set_results = gbk; 设置输出结果的编码为GBK
之后再DOS中插入和查询中文都不会出现乱码!
但是,这只是一次性,当断开数据库后再次连接又会出现之前的情况,就得重新设置。