1. 程式人生 > >解決Django框架下輸出文字亂碼,但是在Mysql中是中文的問題

解決Django框架下輸出文字亂碼,但是在Mysql中是中文的問題

出現網頁顯示亂碼,但是在資料庫中卻正常顯示的問題

更改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.5/"

#Path to the database root
datadir="C:/ProgramData/MySQL/MySQL Server 5.5/Data/"

# The default character set that will be used when a new schema or table is
# created and no character set is defined
character-set-server=utf8

裡面有兩個character-set-server,上面的改成gbk,下面改成utf8
然後輸入net stop mysql ,停止MySQL
再重新啟動MySQL,net start mysql
最後再將資料庫刪掉重新建表輸入