为什么mysql默认为utf-8,但是CMD不能插入汉字

来源:互联网 发布:网络66是什么意思 编辑:程序博客网 时间:2024/05/19 19:40
mysql数据库乱码问题
2009-02-19 19:16

我的mysql数据库状态如下:

 

--------------

D:Program FilesMySQLMySQL Server5.2binmysql.exe Ver 14.13 Distrib 5.2.0-f

alcon-alpha, for Win32 (ia32)

 

Connection id:         30

Current database:

Current user:          root@localhost

SSL:                   Not in use

Using delimiter:       ;

Server version:        5.2.0-falcon-alpha-community-nt MySQL Community Server(

GPL)

Protocol version:      10

Connection:            localhost via TCP/IP

Servercharacterset:   utf8

Db    characterset:   utf8

Clientcharacterset:   utf8

Conn.characterset:   utf8

TCP port:              3306

Uptime:                6 hours 37 min 37 sec

 

Threads: 1 Questions: 230 Slow queries: 0 Opens:25 Flush tables: 1 Open ta

bles: 1 Queries per second avg:%

--------------

 

无论我用jsp页面还是servlet(而且统一为utf-8)向数据库插入中文时出现乱码,显示为:???cmd界面插入中文数据时出现ERROR:1366(HY000)Incorrectstring value:google了很久,试了很多种方法都没用,只有一个地方说的方法有效。就是将MySQL Server5.2中的my.ini中的CLIENT SECTION部分中的default-character-set=utf-8改为default-character-set=GBK,其他的都不变,然后重新打开mysqlcmd界面执行插入操作就ok了。

 

没改之前的my.ini为:

 

# MySQL Server Instance ConfigurationFile

#----------------------------------------------------------------------

 

... ...

 

 

# CLIENT SECTION

#----------------------------------------------------------------------

#

# The following options will be read by MySQLclient applications.

# Note that only client applications shipped byMySQL are guaranteed

# to read this section. If you want your ownMySQL client program to

# honor these values, you need to specify it asan option during the

# MySQL client libraryinitialization.

#

[client]

 

port=3306

 

[mysql]

 

default-character-set=utf8

 

 

# SERVER SECTION

#----------------------------------------------------------------------

 

... ...

 

 

改了之后为:

 

# MySQL Server Instance ConfigurationFile

#----------------------------------------------------------------------

 

 

... ...

 

 

# CLIENT SECTION

#----------------------------------------------------------------------

#

# The following options will be read by MySQLclient applications.

# Note that only client applications shipped byMySQL are guaranteed

# to read this section. If you want your ownMySQL client program to

# honor these values, you need to specify it asan option during the

# MySQL client libraryinitialization.

#

[client]

 

port=3306

 

[mysql]

 

default-character-set=GBK

 

 

# SERVER SECTION

#----------------------------------------------------------------------

 

... ...

 

 

网络上很多高手都说要jspservletmysql的编码要统一,但是统一为utf-8却会出现问题,只有这样改了才ok,至于到底原因在还请高手们多多指教。