黑馬程序員--Mysql中文亂碼解決辦法

  -------android培訓java培訓、期待與您交流! ---------- 

在使用MYSQL時,插入中文字符出現亂碼,中文全被用?代替。馬上google以下。原來是出現這種情況的原因是字符集不匹配造成的。   
在MYSQL中,如果使用缺省的字符集,在建庫、建表時,默認使用的是latin1字符集,爲ISO 8859-1西歐字符集。插入中文字符時,與之不匹配,就會出現亂碼。

要解決此問題,就必須手動將數據庫Server和Client的字符編碼改爲gb2312。配置方法如下:   
打開MYSQL安裝目錄下的my.ini文件,找到如下段落:

[client]

port=3306

[mysql]

default-character-set=latin1

將latin1改爲gb2312.

# 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.1/"

#Path to the database root   
datadir="C:/Documents and Settings/All Users/Application Data/MySQL/MySQL

Server 5.1/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=latin1

將其中的default-character-set=latin1改爲default-character-set=gb2312,然後重啓MYSQL(以前已經亂碼的數據庫要重建).

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章