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

mysql 当插入中文字段时发生“data too long for column”错误

2010-04-01 21:16 621 查看
从MySql5中运行本地脚本创建数据库,当插入中文字段时发生“data too long for column”错误。上网一查,发现多字节用户大都碰到了这种情况。google搜索网上的解决方法大都是要将数据库的编码方式为GBK或UTF8,可我在安装MySql时就选择了UTF8格式。解决方法是:数据库目前是utf-8 ,为了能插入中文,先暂时把
mysql5的my.ini里的一个编码改成gbk,然后插入进去就可以了,如果用mysql自己的那个dos界面查看的话,可能显示是乱码,没关系,然后关闭
mysql服务,重新设置mysql的编码为utf8,然后重启服务器,用navicat这样的工具查看,应该能看到正确的编码,尔不是乱码,这样就可以解决了

 

 

# 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=GBK

# 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:/Program Files/MySQL/MySQL Server 5.0/"

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

重启下就OK了

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐