Mysql中文亂碼解決辦法

在使用MYSQL時,插入中文字符出現亂碼,中文全被用?代替。立刻google如下。原來是出現這種狀況的緣由是字符集不匹配形成的。
在MYSQL中,若是使用缺省的字符集,在建庫、建表時,默認使用的是latin1字符集,爲ISO 8859-1西歐字符集。插入中文字符時,與之不匹配,就會出現亂碼。mysql

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

[client]數據庫

port=3306ide

[mysql]this

default-character-set=latin1google

 

將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] server

# The TCP/IP Port the MySQL Server will listen on
port=3306 it

#Path to installation directory. All paths are usually resolved relative to io

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(之前已經亂碼的數據庫要重建).

相關文章
相關標籤/搜索