mysql乱码问题

 

1、修改在mysql中的my.ini文件(两处):

[client]

port=3306

[mysql]

default-character-set=gbk

 

[mysqld]

# The TCP/IP Port the MySQL Server will listen on
port=3306


#Path to installation directory. All paths are usually resolved relative to this.
basedir="G:/Program Files/MySQL/MySQL Server 5.0/"

#Path to the database root
datadir="G:/Program Files/MySQL/MySQL Server 5.0/Data/"

# The default character set that will be used when a new schema or table is
# created and no character set is defined
default-character-set=
gbk

程序文件编码格式是gbk的话,这里用gbk应该没什么疑问,但是我们的程序文件编码格式是utf8的话,这里也要是gbk,否则要么是用mysql的命令行查询是乱码,或者用某个客户端查询是乱码。

 

2、程序连接数据库的时候加上如下语句:useUnicode=true&characterEncoding=utf-8

我的程序文件编码格式是utf-8的。

 

例如:datasource.url=jdbc:mysql://localhost:3306/davos?useUnicode=true&characterEncoding=utf-8

 

 

修改以上两点,乱码问题应该可以解决了。我是试了好几天才试出来的。希望能给一些人有所帮助。

 

你可能感兴趣的:(数据库)