標籤:
I would not suggest Richies answer, because you are screwing up the data inside the database. You would not fix your problem but try to "hide" it and not being able to perform essential database operations with the crapped data.
If you encounter this error either the data you are sending is not UTF-8 encoded, or your connection is not UTF-8. First, verify, that the data source (a file, ...) really is UTF-8.
Then, check your database connection, you should do this after connecting:
SET NAMES ‘utf8‘;SET CHARACTER SET utf8;
Next, verify that the tables where the data is stored have the utf8 character set:
SELECT `tables`.`TABLE_NAME`, `collations`.`character_set_name`FROM `information_schema`.`TABLES` AS `tables`, `information_schema`.`COLLATION_CHARACTER_SET_APPLICABILITY` AS `collations`WHERE `tables`.`table_schema` = DATABASE() AND `collations`.`collation_name` = `tables`.`table_collation`;
Last, check your database settings:
mysql> show variables like ‘%colla%‘;mysql> show variables like ‘%charac%‘;
If source, transport and destination are UTF-8, your problem is gone;)
另外,安裝完mysql之後,應該運行一下命令來設定編碼為utf-8:
先在命令列運行:status查看編碼是不是utf8。
set character_set_server = ‘utf8‘;set character_set_connection = ‘utf8‘;set character_set_results = ‘utf8‘;set character_set_client = ‘utf8‘;改變database的編碼可以用: alter database db_name default character set ‘utf8‘;
show create table t1; 可以查看錶的schema
mysql 中文亂碼的解決辦法