mysql中文亂碼問題解決方案

來源:互聯網
上載者:User

問題現象:

當向mysql教程5.5插入中文時,會出現類似錯誤

ERROR 1366 (HY000): Incorrect string value: 'xD6xD0xCExC4' for column
問題原因:

Db characterset的字元集設成了latin1

1、先確定資料裡儲存的是否是亂碼:
mysql>select * from yourtable;
查看如果是亂碼的話,就是你插入資料的時候,當前頁面的編碼方式和你mysql的編碼方式不一致。
2、如果排除了以上亂碼的可能,也就是說資料庫教程中能正常儲存中文,就需要檢查你頁面顯示的編碼方式了


解決方案:

找到MYSQL安裝目錄下的my.ini檔案修改:


[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="C:/Program Files/MySQL/MySQL Server 5.0/"

#Path to the database root
datadir="C:/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=gbk

# The default storage engine that will be used when create new tables when
default-storage-engine=INNODB


參考my.cnf

修改mysql的預設字元集是通過修改它的設定檔來實現的


windows下的mysql設定檔是my.ini,一般在安裝目錄下(如C:Program FilesMySQLMySQL Server 5.0),可以直接在這個檔案裡面加上 

default-character-set=gbk #或gb2312,big5,utf8
然後重新啟動mysql 

 查看 MySQL 資料庫伺服器字元集,資料庫字元集和用戶端字元集 

show variables like '%char%'; 

character_set_client,用戶端字元集 

character_set_database,資料庫字元集 

character_set_server,伺服器字元集 

2. 查看 MySQL 資料表(table) 的字元集 

show table status from tablename like '%countries%'; 

3. 查看 MySQL 資料列(column)的字元集。 

show full columns from tablename; 

4. 查看當前安裝的 MySQL 所支援的字元集。 

show char set;

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.