主要解决方向,JAVA与MYSQL中编码要统一。通常采用UTF-8.
1.查询自身MYSQL编码方式
MySQL默认编码是latin1
mysql> show variables like 'character%';
+--------------------------+--------------------------+
| Variable_name | Value |
+--------------------------+--------------------------+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | latin1 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | D:\MySQL\share\charsets\ |
+--------------------------+--------------------------+
2.若项目用UTF8编码,则将MYSQL也改为UTF8编码。通过修改my.ini文件。添加如下几项,再重启MYSQL服务就好。
[mysql]
default-character-set = utf8
[mysql.server]
default-character-set = utf8
[mysqld_safe]
default-character-set = utf8
[client]
default-character-set = utf8
[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci
以上就是本文的全部内容,希望对大家的学习有所帮助.