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

从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了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值