MySQL亂碼的幾種原因

來源:互聯網
上載者:User

MySQL亂碼的幾種原因

MySQL之所以會亂碼,無非是以下幾種原因:

1、存進資料庫之前就亂碼

2、在存進資料庫過程中亂碼

3、存進資料庫後亂碼

想知道在哪裡出現亂碼很簡單,在後台列印一下就知道了。

既然知道問題出在哪裡,那解決方案也很簡單:

1、jsp設定編碼是utf-8,保證傳到背景是utf-8的編碼

2、在資料庫連接上加這麼一段jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8,保證傳輸過程是utf-8的。

3、設定資料庫的編碼為utf-8,在my.ini設定或者在Config設定也行,注意的是my.ini裡default-character-set要改兩處地方

4、url或者easyui亂碼,可以試一下將tomcat的server.xml中的

<Connector port="8080" protocol="HTTP/1.1"               connectionTimeout="20000"               redirectPort="8443"/> 

改為

<Connector port="8080" protocol="HTTP/1.1"               connectionTimeout="20000"               redirectPort="8443" URIEncoding="utf-8"/>

要保證不亂碼,首先要做到編碼要統一,其他問題都好找出來。完。

本文永久更新連結地址:

相關文章

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.