mysql 當插入中文欄位時發生“data too long for column”錯誤

來源:互聯網
上載者:User

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

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.