从MySql5中运行本地脚本建立数据库,当插入中文字段时发生“data too long for column”错误。上网一查,发现多字节用户大都碰到了这种状况。google搜索网上的解决方法大都是要将数据库的编码方式为GBK或UTF8,可我在安装MySql时就选择了UTF8格式。解决方法是:数据库目前是utf-8 ,为了能插入中文,先暂时把
mysql5的my.ini里的一个编码改为gbk,而后插入进去就能够了,若是用mysql本身的那个dos界面查看的话,可能显示是乱码,不要紧,而后关闭
mysql服务,从新设置mysql的编码为utf8,而后重启服务器,用navicat这样的工具查看,应该能看到正确的编码,尔不是乱码,这样就能够解决了mysql
# 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]sql
port=3306数据库
[mysql]服务器
default-character-set=GBKapp
# 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=3306this
#Path to installation directory. All paths are usually resolved relative to this.
basedir="D:/Program Files/MySQL/MySQL Server 5.0/"google
#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=utf8spa
重启下就OK了