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

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,至于到底原因在还请高手们多多指教。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值