关于mysql解决中文乱码问题

来源:互联网 发布:膝盖伸直有响声 知乎 编辑:程序博客网 时间:2024/05/21 03:18

最近使用mysql时出现了中文乱码问题。 作为一名菜鸟程序员,决定记录下来从现在开始的有意义的问题


问题出现在jsp表单提交后出现乱码,问题的起因在哪?  一种可能出现在页面,另一种就应该是出现在数据库。

首先测试了一下页面提交的结果,结果正常。 那问题就应该出现在数据库部分了。

于是启动MYSQL查询了表中的具体数据,果然出现了乱码。

回想自己装MYSQL的过程,没有问题。创建数据库时使用的编码也是对应的utf-8与servlet的编码是一致的。

原来是数据库server本身的问题。数据库默认的编码是lant1。怎么改呢。

# CLIENT SECTION 
# ---------------------------------------------------------------------- 

# The following options will be read by MySQL client applications. 
# Note that only client applications shipped by MySQL are guaranteed 
# to read this section. If you want your own MySQL client program to 
# honor these values, you need to specify it as an option during the 
# MySQL client library initialization. 

[client] 

port=3306 

[mysql] 

default-character-set=latin1 


# SERVER SECTION 
# ---------------------------------------------------------------------- 

# The following options will be read by the MySQL Server. Make sure that 
# you have installed the server correctly (see above) so it reads this 
# file. 

[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="D:/MySQL/MySQL Server 5.0/" 

#Path to the database root 
datadir="D:/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=latin1 

将红字的部分改成 default-character-set=utf-8 或者gbk



0 0