¼s¨ü«È¤á¦nµû¡Aº¡¨¬±zªº©~®a¦¬¯Ç©M­·®æ¡A§K¶O¤V¶q³]­p
«È»s¤Æ¨t²Î®a¨ã¡A¥R¤Àº¡¨¬©~®aªÅ¶¡¾÷¯à»Ý¨D
·h®a¤½¥q²{³õ§K¶O±M¤H¦ô»ù¡A¼t©Ð©î°£¡B¹H³¹«Ø¿v©î°£
±M·~¤uµ{¹Î¶¤¡A¿Ë¤Á¥Î¤ßªA°È±z¡I

­º­¶  ¡E  j2h ½×¾Â ¡E µ{¦¡³]­p°Q½×     ¡E 

mysql 4.1¤¤¤å¶Ã½X°ÝÃD

©ÐªF¡Gªü«O
µoªí®É¶¡¡G2007-03-06


¤j³¡¥÷¤H¤É¯Åwordpress 1.5®É¸I¨ìªº°ÝÃD³£¬O¤¤¤å¶Ã½X¡A¤×¨ä¬O¦pªG­ì¥»¥Î mysql 4.0 ¦Ó¦P®É­n¤É¯Å¨ì mysql 4.1ªº¸Ü¡C

¥D­n­ì¦]¬Omysql 4.1¦b»y¨t¤è­±¼W¥[¤F³\¦h¥\¯à¡A¥¦¥i¥H³]©w»y¨tªº¼h¦¸±q³Ì©³¼hªº server, database ¨ì³æ¤@ table, column, connection ³£¥i¥H³]©w¡A¦Ó°£¤F»y¨t¤§¥~¡AÁÙ¥i¥H«ü©w·f°t¤£¦Pªº collation¡A©Ò¥H²Õ¦X¦Ê¦ÊºØ¡A¥u­n¤@­Ó¿ù¤F´NÃø°k¶Ã½Xªº©R¹B¡C(¦Ó¤§«e¥Îmysql 4.0¬°¦ó¤£¥Î³]©w¤]¤£·|¥X°ÝÃD©O¡H¥D­n­ì¦]¬O¨º®É¹w³]¬O latin-1¡A¥¿¦n¬Û®e¤j³¡¥÷ªºutf-8¦r¤¸¡A©Ò¥H¤£±`¸I¨ì¶Ã½X)

©Ò¥H¦pªG§Aªº±¡ªp¸ò§Ú¤@¼Ë¡A¦P®É­n±N wordpress ±q v1.2¤É¯Å¨ì v1.5, µM«ámysql¤]­n v4.0 ¤É¯Å¨ì v4.1 ªº¸Ü¡A½Ð¬Ý¤U­±¬yµ{¡G

0. ¥ý¶iphpmyadmin§ä¨ì¥i¿é¤J sql queryªºµe­±¡AµM«áÁä¤J¡G

show variables like ¡¥%character%¡¦;

³o¥y¸Ü·|Åã¥Ü¥Ø«e¸ê®Æ®w¨Ï¥Îªº»y¨t³]©w¡A¤@¯ë°ê¥~ªººô¯¸©Î­è¸Ë¦nªº mysql 4.1¹w³]³£¬O latin-1¡C

1 ·s¼Wwordpress blog­n¥Îªºdatabase¦WºÙ¡A¨Ò¦p myblog.

¦pªG§A¼ô±x phpmyadmin ªº¾Þ§@¡A¦bµe­±¤W´N¥i¥H¿ï¾Ü³o­Ó·sdatabase ­n¥Îªº»y¨t¡A

charset ½Ð¿ï¾Ü UTF-8 Unicode (utf8)
collation ½Ð¿ï¾Ü utf8_general_ci (ci ¥Nªí case insensitve ¤j¤p¼g¨S®t)

2¡B§ï database»y¨t¡A¦P¼Ë¦b phpmyadmin ªºqueryµe­±Áä¤J¤U­±¨â¦æ¡G

¦pªG§A¦b¤W¤@¨B¤¤¨S¥¿½T¿ï¾Ü»y¨t¡A©Î¬O¦b¬Ý¨ì¥»¤å«e¤w¸g¥ý«Ø¦ndatabase¤F¤]¨SÃö«Y¡A¥Î¤U­±»yªk¥i¥H§ï¦^¨Ó

alter database myblog
character set utf8;

3¡B¶×¤Jªº sql

¨ì³oùج°¤îmysqlùØ­±¤w¸g¦³¤@­Ó utf-8ªº database, ¥i¥H·Ç³Æ­Ë¸ê®Æ¶i¥h¤F¡A§âª©ªºsql ¤å¦rÀɪ½±µcopy-paste©Î¤W¶Ç¨ì phpmyadmin§Y¥i¡Cª`·N­n§i¶Dphpmyadmin³o­Ó¤å¦rÀɬO utf-8 ½s½Xªº¤~¯à¥¿½T¶×¤J¡C

®Ú¾Ú§Úªº¸gÅç¡AÁ`¬O·|¦³¤@¨â­Ó¤p¦a¤è¥X°ÝÃD¡A¥i¯à­n¤â°Ê­×§ï¤@¤U¤º®e¡A¨Ò¦p±N¬Y¨Ç¤¤¤å¦r¥ý´«¦¨­^¤å¡Aµ¥­Ë¶imysql«á¦A¶iwordpress §ï¦^¨Ó¡C

4¡B§ï wp-db.php ªº³]©w

«e­±´¿¸g´£¹L¡Amysqlªº»y¨t³]©w¬O¦h¼h¦¸ªº¡A«e­±§Ú­Ì§âdatabase»Ptableªº»y¨t³£³]©w¥¿½T¡A¦ýµ{¦¡»Pmysql³s½u®Éªº»y¨t«h¬O¥Ñ connection ¨Ó¨M©w¡A³o³¡¥÷´N­n§ïwordpressªºµ{¦¡½X¡A¦b \wp-includes\wp-db.php ªº²Ä 44¦æ¥[¤W¡G

$this->query(¡¨SET NAMES ¡¥utf8¡¬¡¨);

³o¥y¸Ü·|¦P®É³]©w client, results, connection¤TªÌ¨Ï¥Îªº»y¨t¬° utf-8¡C

¡¯³Ì«áÀˬd¬O§_¥þ³¡§ï¦¨ utf-8

show variables like ¡¥%character%¡¦;

¦¹®É§AÀ³¸Ó·|¬Ý¨ì¤j³¡¥÷Äæ¦ì³£¬Outf-8¤F¡A°£¤F server ³o¶µ¤§¥~¡A¦]¬°§Ú¬O¥Î§O¤Hªºhosting¥D¾÷¡A©Ò¥H¨Sªk¨à§ï³o³¡¥÷¡A¦ý¥­±`°µ®×¤l®É¤j³¡¥÷³£¥i¥Hª½±µ±±ºÞmysql¡A¦¹®É´N¥i¥H¥Î my.ini ³]©w¡G

[mysqld]
default-character-set=utf8

§i¶Dmysql server±Ò°Ê®É­n¥Î utf-8§Y¥i¡C

ªþ±a¤@´£¡A¸g¹L³o¼Ë½Õ®Õªºmysql¡A³s±µ flash - amfphp - php - mysql ¤]§¹¥þ¨S°ÝÃD¡A¥i¥H¤¬¶Ç¤¤¤å/¤é¤å¡C



  • ÃÙ§Uºô¯¸       

    ¼s§Q¤£°Ê²£-ªO¾ô¦b¦a¥Í®Ú³Ì¹ê¦b--·sªO¯S°Ï«ü¦W«×³Ì°ª¡B­È±o±z«H¿àªº¦n©Ð¥ò
    §¹¾ã©Ð°T¡A©Ð«Î¡B©±­±¼öªùºë¿ïª«¥ó¡A¼s§Q¤£°Ê²£ Àu½è¥ò¤¶¡A©Ð«Î¯²¸î¡B¶R½æ¸ê°T³z©ú¡A¥æ©ö¯u¦w¤ß¡I
    ¼s§Q¤£°Ê²£-·sªO¯S°Ï«ü¦W«×³Ì°ª¡B­È±o±z«H¿àªº¦n©Ð¥ò
    ±zªº¦«¥I,¼s§Q¥Î¤ß¬°±zªA°È

  • 1 ¼Ó¦í¤á¡G¹F¤H
    µoªí®É¶¡¡G2007-06-08

    mysql ·|¥X²{¤¤¤å¶Ã½Xªº­ì¦]¤£¥~¥G¤U¦C´XÂI¡G

    ¡÷ mysql server¥»¨­³]©w°ÝÃD¡A¨Ò¦pÁÙ°±¯d¦b latin1

    ¡÷ mysql table ªº»y¨t³]©w°ÝÃD(¥]§t character »P collation)

    ¡÷ «È¤áºÝµ{¦¡(¨Ò¦p php) ªº³s½u»y¨t³]©w°ÝÃD





    mysql 4.1 ¤Î¤§«áªºª©¥»¦b»y¨t¤è­±¼W¥[¤F³\¦h¥\¯à¡A¥¦¥i¥H³]©w»y¨tªº¼h¦¸±q³Ì©³¼hªº server, database ¨ì³æ¤@ table, column, connection ³£¥i¥H³]©w¡A¦Ó°£¤F»y¨t¤§¥~¡AÁÙ¥i¥H«ü©w·f°t¤£¦Pªº collation(®Õ¹ï)¡A©Ò¥H²Õ¦X¦Ê¦ÊºØ¡A¥u­n¤@­Ó¿ù¤F´NÃø°k¶Ã½Xªº©R¹B¡C



    ¶iphpmyadmin§ä¨ì¥i¿é¤J sql queryªºµe­±¡AµM«áÁä¤J¡G

    show variables like '%character%';

    ³o¥y¸Ü·|Åã¥Ü¥Ø«e¸ê®Æ®w¨Ï¥Îªº»y¨t³]©w¡A¤@¯ë°ê¥~ªººô¯¸©Î­è¸Ë¦nªº mysql 4.1¹w³]³£¬O latin-1¡C



    [·s¼W¸ê®Æ®w]

    ¦pªG§A¼ô±x phpmyadmin ªº¾Þ§@¡A¦bµe­±¤W´N¥i¥H¿ï¾Ü«Ø¥ß·s database ­n¥Îªº»y¨t¡A

    charset ½Ð¿ï¾Ü UTF-8 Unicode (utf8)

    collation ½Ð¿ï¾Ü utf8_general_ci (ci ¥Nªí case insensitve ¤j¤p¼g¨S®t)



    [­×§ï¸ê®Æ®w]

    §ï database»y¨t¡A¦P¼Ë¦b phpmyadmin ªºqueryµe­±Áä¤J¤U­±¨â¦æ¡G

    alter database myblog

    character set utf8;





    «e­±´¿¸g´£¹L¡Amysqlªº»y¨t³]©w¬O¦h¼h¦¸ªº¡A«e­±§Ú­Ì§âdatabase»Ptableªº»y¨t³£³]©w¥¿½T¡A¦ýµ{¦¡»Pmysql³s½u®Éªº»y¨t«h¬O¥Ñ connection ¨Ó¨M©w¡A³o³¡¥÷´N­n¨Ï¥Îµ{¦¡½X

    mysql_query("SET NAMES 'utf8'");

    ³o¥y¸Ü·|¦P®É³]©w client, results, connection¤TªÌ¨Ï¥Îªº»y¨t¬° utf-8¡C



    ³Ì«áÀˬd¬O§_¥þ³¡§ï¦¨ utf-8

    show variables like '%character%';



    ¦¹®É§AÀ³¸Ó·|¬Ý¨ì¤j³¡¥÷Äæ¦ì³£¬Outf-8¤F¡A°£¤F server ³o¶µ¤§¥~¡A¦pªG¬O¥Î§O¤Hªº hosting ¥D¾÷¡A´N¨Sªk¨à§ï³o³¡¥÷¡A¦ý¥­±`°µ®×¤l®É¤j³¡¥÷³£¥i¥Hª½±µ±±ºÞmysql¡A¦¹®É´N¥i¥H¥Î my.ini ³]©w¡G



    [mysqld]

    default-character-set=utf8

    §i¶Dmysql server±Ò°Ê®É­n¥Î utf-8§Y¥i¡C







    ¡¯mysql¤¤¤å¶Ã½X¥²³Ó¸Ñ¨Mªk

    1¡Bmysql ±Ò°Ê®É·|Ū¨ú¤@­Ó¹w³]ªº config ÀÉ¡A¤@¯ë¦WºÙ¬° my.ini¡A¦Ó¥¦·|¨ì¤U¦C¨â¦ì¸m¥h´M§ä³o­ÓÀɮסG

    C:\windows\my.ini ¤]´N¬O§@·~¨t²Îªº¦w¸Ë¥Ø¿ý¡A¤]¦³¥i¯à¬O C:\winnt\my.ini

    C:\:my.cnf ¤]´N¬O C disk ªº®Ú¥Ø¿ý





    2¡Bmy.ini ùتº¤º®e¬°¡G

    [mysqld]

    default-character-set=utf8



    [client]

    default-character-set=utf8

    init_connect='SET NAMES utf8'



    ¨ä¤¤ mysqld ¬O«ü©w server ±Ò°Ê®É­n¥Îªº»y¨t¡A¦ý¦pªG³oùس]©w¬° utf8 ¥i¯à·|Åý³\¦h­^¤å³nÅ餣¶}¤ß¡A¨Ò¦p osCommerce/mediaWiki/wordpress/drupal/gregarius¡A©Ò¥H³oùØ«Øij³]¦¨ latin1¡C­n¨Ï¥Îutf8¤¤¤åªº¤H¡A¥u­n°O±o«Ø¸ê®Æ®w®É±N¥¦³]¦¨utf8¡AÅý¤¤¤åµ{¦¡¥¿½Tªº¨Ï¥Î utf8 »P¥¦·¾³q§Y¥i¡C





    ¤U­±ªº client «h¬O³]©w·í client ³s½u®É­n¨Ï¥Î¤°»ò»y¨t¡A¦ý¥i±¤ªº¬O³o­Ó³]©w¤£¬O¨C­Ó client ³£·|³¾¥¦¡A°ò¥»¤W¥u¦³ mysql ¦Û¤w®aªºµ{¦¡¡A¨Ò¦p mysql.exe, mysqld.exe, mysqladmin.exe ©Î¬O MySQL Control Center ³oºØµ{¦¡·|¥hŪ¨ú³o­Ó³]©wÀɵM«á§ï¥Î utf8 ³s½u¡C



    ©Ò¥H³q±`·|¥Î¤@­Ó¿W¥ßªºÀɮרӳB²z mysql connectionªº³]©w¡A¨Ò¦p¡G



    PHP:





    //database connection details.

    $host = "localhost";

    $link = mysql_connect($host, "xxx", "xxx");

    mysql_query("SET NAMES 'utf8'");

    mysql_select_db("your_table_name_here", $link);

    ?>




    ½Ðª`·N¦b mysql_connect«á²Ä¤­¦æªº¦a¤è¦³¥[¤W¤@­Ó "set names 'utf8' "ªº«ü¥O¡A§i¶Dmysql ³o­Ó connection ¤§«áªº³s½u¤º®e³£­n¨Ï¥Îutf8¡A¸g¹L³o¼Ë³]©w«á¡A³q±`´N¥i¥H¸Ñ¨M¤j³¡¥÷°ÝÃD¡C



    ±q³oùؤ]¥i¥H±À·Q±oª¾¡A¦pªG§A¦³¥Î¬YºØ custom connection pooling ¾÷¨î¡A´N­n°O±o¦b¨C¦¸«Ø¥ß·sªº connection «á¥ß§Y³]©w¬° utf8¡C



    2 ¼Ó¦í¤á¡G·s¤â
    µoªí®É¶¡¡G2007-06-08

    < ?
    //database connection details.
    $host = "localhost";
    $link = mysql_connect($host, "xxx", "xxx");
    mysql_query("SET NAMES 'Big5'");
    mysql_select_db("your_table_name_here", $link);
    ?>

    ¥Î³o­Ó¤èªk¤]¥i¥H..
    mysql_connect «á¦³¥[¤W¤@­Ó "set names ¡¥Big5¡¬ " «ü¥O
    §i¶D mysql ³o­Ó connection ¤§«áªº³s½u¤º®e³£­n¨Ï¥ÎBig5
    ¸g¹L³o¼Ë³]©w«á.. ³q±`´N¥i¥H¸Ñ¨M¤j³¡¥÷°ÝÃD



    ¡@¦@ 2 ¤H¦^À³¡@¡@¿ï¾Ü­¶¼Æ ¡i²Ä1 ­¶¡j 

    ©m¦W¡G
    §G§i¤º®e¡G
    ¨ä¥L¿ï¶µ: