mysql中文亂碼是php jsp初學者常碰到的事情,解決方法有很多,下面我們介紹一下在my.cnf中配置的方法.
問題現象:當向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
- --Vevb.com
- # 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;
新聞熱點
疑難解答