¸ê²`³]­p¤½¥q¡A´£¨Ñ±M·~«Ç¤º¸ËæC³]­pªA°È
¥H¶q¨î»ù¡Aªá¤p¿ú¨Éºë½o©~®a³]­p­·®æ
«È·½ºô«Ç¤º¥~©ÛµP¹êÁZ¯}¸U¥ó¡A§ä¹ï³]­p®v¡A¼s§i®ÄªG¤@¯Å´Î
§÷½è¿ï¾Ü¦h¡AÅwªï¨Ó¹q¬¢¸ß

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

[°Q½×]mysql¤¤¤å¶Ã½Xªº­ì¦]

©ÐªF¡G¹F¤H
µoªí®É¶¡¡G2007-07-28
[ÀËÁ|]


mysql¤¤¤å¶Ã½Xªº­ì¦]
¡¯mysql¤¤¤å¶Ã½Xªº­ì¦]
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_c

¨ä¤¤ 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:


[Copy to clipboard]CODE:
//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




  • ÃÙ§Uºô¯¸       

    ¼s§Q¤£°Ê²£-·sªO¯S°Ï«ü¦W«×³Ì°ª¡B­È±o±z«H¿àªº¦n©Ð¥ò
    ±zªº¦«¥I,¼s§Q¥Î¤ß¬°±zªA°È
    ¼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



  • ¡@¦@ 0 ¤H¦^À³

    ©m¦W¡G
    §G§i¤º®e¡G