mysql 中文亂碼的解決辦法

來源:互聯網
上載者:User

標籤:

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 中文亂碼的解決辦法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.