Mysql資料庫亂碼與編碼問題篩查

來源:互聯網
上載者:User

[client]

[mysqld]

collation_server = utf8_general_ci

character_set_server = utf8

[mysql]

[mysqldump]

3. 資料表編碼

/*!40101SET @saved_cs_client     =@@character_set_client */;

/*!40101SET character_set_client = utf8 */;

CREATETABLE `access` (

  `id` int(8) unsigned NOT NULL AUTO_INCREMENT,

  `role_id` smallint(6) unsigned NOT NULL,

  `node_id` smallint(6) unsigned NOT NULL,

  PRIMARY KEY (`id`),

  KEY `nodeId` (`node_id`)

)ENGINE=MyISAM AUTO_INCREMENT=364 DEFAULTCHARSET=utf8;

/*!40101 SET character_set_client = @saved_cs_client */;

4. 轉存的時候

有時候需要轉存資料庫,但是好好的資料庫轉到新庫就亂碼了,你可能需要:

#mysqldump --default-character-set utf8 -u root -pmypass mydb> mydb.sql

5. 查詢的時候

有時候,雖然mysql、資料庫、資料表以及匯出的資料sql檔案編碼都沒問題,但是query出來仍然出現亂碼,可能是因為,在query的時候也需要設定編碼,函數名稱大同小異,在php+mysql中是:

mysql_query('set names utf8');

以上。

相關文章

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.