程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> MySQL綜合教程 >> mysql中文亂碼的完美解決方案,mysql亂碼解決方案

mysql中文亂碼的完美解決方案,mysql亂碼解決方案

編輯:MySQL綜合教程

mysql中文亂碼的完美解決方案,mysql亂碼解決方案


問題描述: mysql插入中文時顯示為亂碼或"?"號

解決方案:

修改mysql的my.ini配置

[mysql]
default_character_set=utf8
[mysqld]
character_set_server=utf8

 

 

 

 

//以下內容為測試記錄內容,完全可以忽略不讀,但為了增加可信度,還是附上了:)

show variables like "%char%";

默認:

+--------------------------+---------------------------------------------------+

| character_set_client     | gbk                                               |

| character_set_connection | gbk                                               |

| character_set_database   | latin1                                            |

| character_set_filesystem | binary                                            |

| character_set_results    | gbk                                               |

| character_set_server     | latin1                                            |

| character_set_system     | utf8                                              |

| character_sets_dir       | c:\wamp\bin\mysql\mysql5.6.17\share\charsets\ |

+--------------------------+---------------------------------------------------+

(本次啟動有效,治標不治本)

set names utf8:

+--------------------------+---------------------------------------------------+

| character_set_client     | utf8                                               |

| character_set_connection | utf8                                               |

| character_set_database   | latin1                                            |

| character_set_filesystem | binary                                            |

| character_set_results    | utf8                                               |

| character_set_server     | latin1                                            |

| character_set_system     | utf8                                              |

| character_sets_dir       | c:\wamp\bin\mysql\mysql5.6.17\share\charsets\ |

+--------------------------+---------------------------------------------------+

(永久有效)

my.ini

[client]

default_character_set=utf8

+--------------------------+---------------------------------------------------+

| character_set_client     | utf8                                               |

| character_set_connection | utf8                                               |

| character_set_database   | latin1                                            |

| character_set_filesystem | binary                                            |

| character_set_results    | utf8                                               |

| character_set_server     | latin1                                            |

| character_set_system     | utf8                                              |

| character_sets_dir       | c:\wamp\bin\mysql\mysql5.6.17\share\charsets\ |

+--------------------------+---------------------------------------------------+

(永久有效,效果同[client]修改)

my.ini

[mysql]

default_character_set=utf8

+--------------------------+---------------------------------------------------+

| character_set_client     | utf8                                               |

| character_set_connection | utf8                                               |

| character_set_database   | latin1                                            |

| character_set_filesystem | binary                                            |

| character_set_results    | utf8                                               |

| character_set_server     | latin1                                            |

| character_set_system     | utf8                                              |

| character_sets_dir       | c:\wamp\bin\mysql\mysql5.6.17\share\charsets\ |

+--------------------------+---------------------------------------------------+

(永久有效,中文完美顯示,避免了每次Insert數據前都先要set names utf8一下)

my.ini

[mysql]

default_character_set=utf8

[mysqld]

character_set_server=utf8

+--------------------------+---------------------------------------------------+

| character_set_client     | utf8                                               |

| character_set_connection | utf8                                               |

| character_set_database   | utf8                                            |

| character_set_filesystem | binary                                            |

| character_set_results    | utf8                                               |

| character_set_server     | utf8                                            |

| character_set_system     | utf8                                              |

| character_sets_dir       | c:\wamp\bin\mysql\mysql5.6.17\share\charsets\ |

+--------------------------+---------------------------------------------------+

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved