在mysql5.5 command line client上面看到的
+----+-------+-----------+---------------------+ | id | state | nickname | createtime | +----+-------+-----------+---------------------+ | 1 | 1 | 鍝堝搱鍝? | 2014-08-12 21:56:11 | | 2 | 2 | 浣犲ソ | 2014-08-12 22:17:14 | | 3 | 3 | MySQ | 2014-08-12 22:33:39 | | 4 | 2 | 浣犲ソ | 2014-08-12 22:38:12 | +----+-------+-----------+---------------------+ 在navicat上面看到的启动console看到的
+----+-------+----------+---------------------+ | id | state | nickname | createtime | +----+-------+----------+---------------------+ | 1 | 1 | 哈哈哈 | 2014-08-12 21:56:11 | | 2 | 2 | 你好 | 2014-08-12 22:17:14 | | 3 | 3 | MySQ | 2014-08-12 22:33:39 | | 4 | 2 | 你好 | 2014-08-12 22:38:12 | +----+-------+----------+---------------------+
在client中语句
insert into days_user values(3,3,'MySQL支持的字符集和校对',sysdate());
> insert into days_user values(3,3,'MySQL支持的字符集和校对',sysdate()); 1366 (HY000): Incorrect string value: '\xB3\xD6\xB5\xC4\xD7\xD6...' for column 'nickname' at row 1
在console正确的插入了 +----+-------+-------------------------+---------------------+ | id | state | nickname | createtime | +----+-------+-------------------------+---------------------+ | 1 | 1 | 哈哈哈 | 2014-08-12 21:56:11 | | 2 | 2 | 你好 | 2014-08-12 22:17:14 | | 3 | 3 | MySQ | 2014-08-12 22:33:39 | | 4 | 2 | 你好 | 2014-08-12 22:38:12 | | 5 | 3 | MySQL支持的字符集和校对 | 2014-08-12 22:45:38 | +----+-------+-------------------------+---------------------+
mysql> SHOW VARIABLES LIKE 'collation_%'; +----------------------+-----------------+ | Variable_name | Value | +----------------------+-----------------+ | collation_connection | utf8_general_ci | | collation_database | utf8_general_ci | | collation_server | utf8_general_ci | +----------------------+-----------------+
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 |
Java中的jdbc配置:
jdbc_url=jdbc:mysql://localhost:3306/mydays?useUnicode=true&characterEncoding=utf-8
还是不行哦,我的操作系统的问题?
######
utf8 && utf-8
傻傻分不清楚. ######数据库中可以选择的编码方式就是“utf8”,没有utf-8,应该都是一个意思吧,书写的方式有所差异罢了######应该是Mybatis在存储转换过程中转码的问题。######
哦,你没错,mysql引擎默认引用latin1(iso-8859-1) ,你进行mysql命令行,选择数据库后用status命令看一下,除数据库外,其它的都应该是latin1编码,
解决方式 :使用set names 'utf-8',全部设置在utf-8编码,就不是乱码了。
其实你那里中文是没有乱码的,latin1支持所有的编码,你用HeidiSQL工具连接上你的mysql ,它能将底层的latin1转为 utf-8。 ######设置如下,还是无法正常插入中文:
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 | C:\Program Files\MySQL\MySQL Server 5.5\share\charsets\ |
######你的项目编码是什么?######utf-8######
怀疑你的字符串并没有使用UTF8编码。
你试试在mysql交互式命令行下以utf8编码插入数据试试 ######也可以检查下页面的编码和浏览器显示用的编码######你可以试试在存入数据库前是否已经乱码,也就是页面传递时乱码没有!######
SHOW VARIABLES LIKE 'collation_%';
+----------------------+-----------------+ | Variable_name | Value | +----------------------+-----------------+ | collation_connection | utf8_general_ci | | collation_database | utf8_general_ci | | collation_server | utf8_unicode_ci | +----------------------+-----------------+ 有可能是 这个 collation_connection 的原因,
使用set collation_connection=utf8_general_ci;提示成功,查询也能查到,
在关闭了之后,再次查询,又恢复到了latin1