您的位置:首页 > 数据库 > MySQL

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

2013-07-14 10:06 597 查看
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,其他的都不变,然后重新打开mysql的cmd界面执行插入操作就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

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

... ...

网络上很多高手都说要jsp、servlet、mysql的编码要统一,但是统一为utf-8却会出现问题,只有这样改了才ok,至于到底原因在还请高手们多多指教。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐