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