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這樣的工具查看,應該能看到正確的編碼,爾不是亂碼,這樣就能夠解決了
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=3306
this


#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=utf8
spa

重啓下就OK了

相關文章
相關標籤/搜索