MySQL Order ByË÷ÒýÓÅ»¯
ÔÚһЩÇé¿öÏ£¬MySQL¿ÉÒÔÖ±½ÓʹÓÃË÷ÒýÀ´Âú×ãÒ»¸ö ORDER BY »ò GROUP BY ×Ó¾ä¶øÎÞÐè×ö¶îÍâµÄÅÅÐò¡£¾¡¹Ü ORDER BY ²»ÊǺÍË÷ÒýµÄ˳Ðò׼ȷƥÅ䣬Ë÷Òý»¹ÊÇ¿ÉÒÔ±»Óõ½£¬Ö»Òª²»ÓõÄË÷Òý²¿·ÖºÍËùÓеĶîÍâµÄ ORDER BY ×Ö¶ÎÔÚ WHERE ×Ó¾äÖж¼±»°üÀ¨ÁË¡£ ¡¡¡¡Ê¹ÓÃË÷ÒýµÄMySQL Order By ¡¡¡¡ÏÂÁеļ¸¸ö²éѯ¶¼»áʹÓÃË÷ÒýÀ´½â¾ö ORDER BY »ò GROUP BY ²¿·Ö£º SELECT * from t1 ORDER BY key_part1,key_part2,... ; SELECT * from t1 WHERE key_part1=constant ORDER BY key_part2; SELECT * from t1 WHERE key_part1=constant GROUP BY key_part2; SELECT * from t1 ORDER BY key_part1 DESC, key_part2 DESC; SELECT * from t1 WHERE key_part1=1 ORDER BY key_part1 DESC, key_part2 DESC; ¡¡¡¡²»Ê¹ÓÃË÷ÒýµÄMySQL Order By ¡¡¡¡ÔÚÁíһЩÇé¿öÏ£¬MySQLÎÞ·¨Ê¹ÓÃË÷ÒýÀ´Âú×ã ORDER BY£¬¾¡¹ÜËü»áʹÓÃË÷ÒýÀ´ÕÒµ½¼Ç¼À´Æ¥Åä WHERE ×Ӿ䡣ÕâЩÇé¿öÈçÏ£º ¡¡¡¡* ¶Ô²»Í¬µÄË÷Òý¼ü×ö ORDER BY £º SELECT * from t1 ORDER BY key1, key2; ¡¡¡¡* ÔÚ·ÇÁ¬ÐøµÄË÷Òý¼ü²¿·ÖÉÏ×ö ORDER BY£º SELECT * from t1 WHERE key2=constant ORDER BY key_part2; ¡¡¡¡* ͬʱʹÓÃÁË ASC ºÍ DESC£º SELECT * from t1 ORDER BY key_part1 DESC, key_part2 ASC; * ÓÃÓÚËÑË÷¼Ç¼µÄË÷Òý¼üºÍ×ö ORDER BY µÄ²»ÊÇͬһ¸ö£º SELECT * from t1 WHERE key2=constant ORDER BY key1; ¡¡¡¡* Óкܶà±íÒ»Æð×öÁ¬½Ó£¬¶øÇÒ¶ÁÈ¡µÄ¼Ç¼ÖÐÔÚ ORDER BY ÖеÄ×ֶζ¼²»È«ÊÇÀ´×ÔµÚÒ»¸ö·Ç³£ÊýµÄ±íÖУ¨Ò²¾ÍÊÇ˵£¬ÔÚ EXPLAIN ·ÖÎöµÄ½á¹ûÖеĵÚÒ»¸ö±íµÄÁ¬½ÓÀàÐͲ»ÊÇ const£©¡£ * ʹÓÃÁ˲»Í¬µÄ ORDER BY ºÍ GROUP BY ±í´ïʽ¡£ ¡¡¡¡* ±íË÷ÒýÖеļǼ²»ÊÇ°´Ðò´æ´¢¡£ÀýÈ磬HASH ºÍ HEAP ±í¾ÍÊÇÕâÑù¡£ ¡¡¡¡Í¨¹ýÖ´ÐÐ EXPLAIN SELECT ... ORDER BY£¬¾ÍÖªµÀMySQLÊÇ·ñÔÚ²éѯÖÐʹÓÃÁËË÷Òý¡£Èç¹û Extra ×ֶεÄÖµÊÇ Using filesort£¬Ôò˵Ã÷MySQLÎÞ·¨Ê¹ÓÃË÷Òý¡£ÏêÇéÇë¿´"7.2.1 EXPLAIN Syntax (Get Information About a SELECT)"¡£µ±±ØÐë¶Ô½á¹û½øÐÐÅÅÐòʱ£¬MySQL 4.1ÒÔÇ° ËüʹÓÃÁËÒÔÏ filesort Ëã·¨£º ¡¡¡¡1. ¸ù¾ÝË÷Òý¼ü¶ÁÈ¡¼Ç¼£¬»òÕßɨÃèÊý¾Ý±í¡£ÄÇЩÎÞ·¨Æ¥Åä WHERE ·Ö¾äµÄ¼Ç¼¶¼»á±»ÂÔ¹ý¡£ ¡¡¡¡2. ÔÚ»º³åÖÐÿÌõ¼Ç¼¶¼ÓÃÒ»¸ö‘¶Ô’´æ´¢ÁË2¸öÖµ£¨Ë÷Òý¼ü¼°¼Ç¼ָÕ룩¡£»º³åµÄ´óСÒÀ¾Ýϵͳ±äÁ¿ sort_buffer_size µÄÖµ¶ø¶¨¡£ ¡¡¡¡3. µ±»º³åÂýÁËʱ£¬¾ÍÔËÐÐ qsort£¨¿ìËÙÅÅÐò£©²¢½«½á¹û´æ´¢ÔÚÁÙʱÎļþÖС£½«´æ´¢µÄ¿éÖ¸Õë±£´æÆðÀ´£¨Èç¹ûËùÓ
Ïà¹ØÎĵµ£º
1 Apache
ÐÞ¸Ä documentroot ¸ùĿ¼
directory ·ÃÎʸùĿ¼ȨÏÞ
directoryindex ĬÈÏÊ×Ò³ ......
Ò»¡¢MySQL »ñµÃµ±Ç°ÈÕÆÚʱ¼ä º¯Êý
1.1 »ñµÃµ±Ç°ÈÕÆÚ+ʱ¼ä£¨date + time£©º¯Êý£ºnow()
mysql> select now();
+---------------------+
| now() |
+---------------------+
| 2008-08-08 22:20:46 |
+---------------------+
³ýÁË now() º¯ÊýÄÜ»ñµÃµ±Ç°µÄÈÕÆÚʱ¼äÍ⣬MySQL Öл¹ÓÐÏÂÃæµÄº¯Êý£º
......
Óöµ½Ò»¸öÎÊÌâÊÇÔÚMySQLÃüÁîÐвåÈëÖÐÎÄÊý¾Ý»òÕß²éѯÖÐÎÄÊý¾Ýʱ³öÏÖÂÒÂ룬»òÕßÏÔʾ²»¶Ô¡£
ÔÚÃüÁîÐÐÊäÈë:show variables like ‘character_set_%’;
²é¿´µ±Ç°ÅäÖõıàÂ룻
ÔÚÃüÁîÐÐÊäÈë :set names utf8;
ÔòµÈͬÓÚ
set character_set_client=utf8;
set character_set_results ......