MySQL資料由程式存入時出現???亂碼
mysql的show variables like '%character%';內容
+--------------------------+-- --------------------------+
| Variable_name | Value |
+--------------------------+-- --------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |====>問題出在這裡
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+-- --------------------------+
在windows的my.ini linux在/etc/my.cnf
在檔案中加入
[mysqld]
character-set-server=utf8
修正後重新啟動MySQL
show variables like 'character_set%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |====>改成UTF8
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
程式重新存入,資料正常
留言
張貼留言