Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

MySQLÐÔÄÜÓÅ»¯µÄ×î¼Ñ20+Ìõ¾­Ñé

½ñÌ죬Êý¾Ý¿âµÄ²Ù×÷Ô½À´Ô½³ÉΪÕû¸öÓ¦ÓõÄÐÔÄÜÆ¿¾±ÁË£¬Õâµã¶ÔÓÚWebÓ¦ÓÃÓÈÆäÃ÷ÏÔ¡£¹ØÓÚÊý¾Ý¿âµÄÐÔÄÜ£¬Õâ²¢²»Ö»ÊÇDBA²ÅÐèÒªµ£ÐĵÄÊ£¬¶øÕâ¸üÊÇÎÒÃdzÌÐòÔ±ÐèҪȥ¹Ø×¢µÄÊÂÇé¡£µ±ÎÒÃÇÈ¥Éè¼ÆÊý¾Ý¿â±í½á¹¹£¬¶Ô²Ù×÷Êý¾Ý¿âʱ£¨ÓÈÆäÊDzé±íʱµÄSQLÓï¾ä£©£¬ÎÒÃǶ¼ÐèҪעÒâÊý¾Ý²Ù×÷µÄÐÔÄÜ¡£ÕâÀÎÒÃDz»»á½²¹ý¶àµÄSQLÓï¾äµÄÓÅ»¯£¬¶øÖ»ÊÇÕë¶ÔMySQLÕâÒ»WebÓ¦ÓÃ×î¶àµÄÊý¾Ý¿â¡£Ï£ÍûÏÂÃæµÄÕâЩÓÅ»¯¼¼ÇɶÔÄãÓÐÓá£
1. Ϊ²éѯ»º´æÓÅ»¯ÄãµÄ²éѯ
´ó¶àÊýµÄMySQL·þÎñÆ÷¶¼¿ªÆôÁ˲éѯ»º´æ¡£ÕâÊÇÌá¸ßÐÔ×îÓÐЧµÄ·½·¨Ö®Ò»£¬¶øÇÒÕâÊDZ»MySQLµÄÊý¾Ý¿âÒýÇæ´¦ÀíµÄ¡£µ±ÓкܶàÏàͬµÄ²éѯ±»Ö´ÐÐÁ˶à´ÎµÄʱºò£¬ÕâЩ²éѯ½á¹û»á±»·Åµ½Ò»¸ö»º´æÖУ¬ÕâÑù£¬ºóÐøµÄÏàͬµÄ²éѯ¾Í²»ÓòÙ×÷±í¶øÖ±½Ó·ÃÎÊ»º´æ½á¹ûÁË¡£
ÕâÀï×îÖ÷ÒªµÄÎÊÌâÊÇ£¬¶ÔÓÚ³ÌÐòÔ±À´Ëµ£¬Õâ¸öÊÂÇéÊǺÜÈÝÒ×±»ºöÂԵġ£ÒòΪ£¬ÎÒÃÇijЩ²éѯÓï¾ä»áÈÃMySQL²»Ê¹Óûº´æ¡£Çë¿´ÏÂÃæµÄʾÀý£º
ÉÏÃæÁ½ÌõSQLÓï¾äµÄ²î±ð¾ÍÊÇ CURDATE() £¬MySQLµÄ²éѯ»º´æ¶ÔÕâ¸öº¯Êý²»Æð×÷Óá£ËùÒÔ£¬Ïñ NOW() ºÍ RAND() »òÊÇÆäËüµÄÖîÈç´ËÀàµÄSQLº¯Êý¶¼²»»á¿ªÆô²éѯ»º´æ£¬ÒòΪÕâЩº¯ÊýµÄ·µ»ØÊǻ᲻¶¨µÄÒ×±äµÄ¡£ËùÒÔ£¬ÄãËùÐèÒªµÄ¾ÍÊÇÓÃÒ»¸ö±äÁ¿À´´úÌæMySQLµÄº¯Êý£¬´Ó¶ø¿ªÆô»º´æ¡£
2. EXPLAIN ÄãµÄ SELECT ²éѯ
ʹÓà EXPLAIN ¹Ø¼ü×Ö¿ÉÒÔÈÃÄãÖªµÀMySQLÊÇÈçºÎ´¦ÀíÄãµÄSQLÓï¾äµÄ¡£Õâ¿ÉÒÔ°ïÄã·ÖÎöÄãµÄ²éѯÓï¾ä»òÊDZí½á¹¹µÄÐÔÄÜÆ¿¾±¡£
EXPLAIN µÄ²éѯ½á¹û»¹»á¸æËßÄãÄãµÄË÷ÒýÖ÷¼ü±»ÈçºÎÀûÓõģ¬ÄãµÄÊý¾Ý±íÊÇÈçºÎ±»ËÑË÷ºÍÅÅÐòµÄ……µÈµÈ£¬µÈµÈ¡£
ÌôÒ»¸öÄãµÄSELECTÓï¾ä£¨ÍƼöÌôÑ¡ÄǸö×Ôӵģ¬Óжà±íÁª½ÓµÄ£©£¬°Ñ¹Ø¼ü×ÖEXPLAIN¼Óµ½Ç°Ãæ¡£Äã¿ÉÒÔʹÓÃphpmyadminÀ´×öÕâ¸öÊ¡£È»ºó£¬Äã»á¿´µ½Ò»Õűí¸ñ¡£ÏÂÃæµÄÕâ¸öʾÀýÖУ¬ÎÒÃÇÍü¼Ç¼ÓÉÏÁËgroup_idË÷Òý£¬²¢ÇÒÓбíÁª½Ó£º
µ±ÎÒÃÇΪ group_id ×ֶμÓÉÏË÷Òýºó£º
ÎÒÃÇ¿ÉÒÔ¿´µ½£¬Ç°Ò»¸ö½á¹ûÏÔʾËÑË÷ÁË 7883 ÐУ¬¶øºóÒ»¸öÖ»ÊÇËÑË÷ÁËÁ½¸ö±íµÄ 9 ºÍ 16 ÐС£²é¿´rowsÁпÉÒÔÈÃÎÒÃÇÕÒµ½Ç±ÔÚµÄÐÔÄÜÎÊÌâ¡£
3. µ±Ö»ÒªÒ»ÐÐÊý¾ÝʱʹÓà LIMIT 1
µ±Äã²éѯ±íµÄÓÐЩʱºò£¬ÄãÒѾ­ÖªµÀ½á¹ûÖ»»áÓÐÒ»Ìõ½á¹û£¬µ«ÒòΪÄã¿ÉÄÜÐèҪȥfetchÓα꣬»òÊÇÄãÒ²Ðí»áÈ¥¼ì²é·µ»ØµÄ¼Ç¼Êý¡£
ÔÚÕâÖÖÇé¿öÏ£¬¼ÓÉÏ LIMIT 1 ¿ÉÒÔÔö¼ÓÐÔÄÜ¡£ÕâÑùÒ»Ñù£¬MySQLÊý¾Ý¿âÒýÇæ»áÔÚÕÒµ½Ò»ÌõÊý¾ÝºóÍ£Ö¹ËÑË÷£¬¶ø²»ÊǼÌÐøÍùºó²éÉÙÏÂÒ»Ìõ·ûºÏ¼Ç¼µÄÊý¾Ý¡£
ÏÂÃæµÄʾÀý£¬Ö»ÊÇΪÁËÕÒÒ»ÏÂÊÇ·ñÓГÖйú”µÄÓû§£¬ºÜÃ÷ÏÔ£¬ºóÃæµÄ»á±ÈÇ°ÃæµÄ¸üÓÐЧÂÊ¡££¨Çë×¢Ò⣬µÚÒ»Ìõ


Ïà¹ØÎĵµ£º

MYSQLÍâ¼ü(Foreign Key)µÄʹÓÃ


ÔÚMySQL 3.23.44°æ±¾ºó£¬InnoDBÒýÇæÀàÐ͵ıíÖ§³ÖÁËÍâ¼üÔ¼Êø¡£
Íâ¼üµÄʹÓÃÌõ¼þ£º
1.Á½¸ö±í±ØÐëÊÇ
InnoDB±í£¬MyISAM±íÔÝʱ²»Ö§³ÖÍâ¼ü£¨¾Ý˵ÒÔºóµÄ°æ±¾ÓпÉÄÜÖ§³Ö£¬µ«ÖÁÉÙÄ¿Ç°²»Ö§³Ö£©£»
2.Íâ¼üÁбØÐ뽨Á¢ÁËË÷Òý£¬MySQL
4.1.2ÒÔºóµÄ°æ±¾ÔÚ½¨Á¢Íâ¼üʱ»á×Ô¶¯´´½¨Ë÷Òý£¬µ«Èç¹ûÔÚ½ÏÔçµÄ°æ±¾ÔòÐèÒªÏÔʾ½¨Á¢£»
3.Íâ¼ü¹Øϵµ ......

mysql µ¼Èëµ¼³öÊý¾Ý·½·¨

1:>;create databases newname(ÔÚеÄserverÉϽ¨Á¢¿ÕµÄÊý¾Ý¿â)
2:#/usr/local/mysql/bin/mysqldump databasename >;*.sql(ÔھɵķþÎñÆ÷Éϵ¼³öÊý¾Ý¿â)
3:#/usr/local/mysql/bin/mysql databasename < *.sql(ÔÚеķþÎñÆ÷Éϵ¼Èë*.sql) ......

ubuntu MySQL°²×°Ö¸ÄÏ

°²×° MySQL£¬¿ÉÒÔÔÚÖÕ¶ËÌáʾ·ûºóÔËÐÐÏÂÁÐÃüÁ
sudo apt-get install mysql-server
sudo apt-get install mysql-client
sudo apt-get install php5-mysql
// °²×°php5-mysql Êǽ«phpºÍmysqlÁ¬½ÓÆðÀ´
Ò»µ©°²×°Íê³É£¬MySQL ·þÎñÆ÷Ó¦¸Ã×Ô¶¯Æô¶¯¡£Äú¿ÉÒÔÔÚÖÕ¶ËÌáʾ·ûºóÔËÐÐÒÔÏÂÃüÁîÀ´¼ì²é MySQL ·þÎñÆ÷ÊÇ·ñÕýÔÚÔËÐУº
s ......

WEB³ÌÐòÔ±ÐèÒªÕÆÎÕµÄÊ®´óMySQLÓÅ»¯¼¼ÇÉ

1.ÓÅ»¯ÄãµÄMySQL²éѯ»º´æ
ÔÚMySQL·þÎñÆ÷ÉϽøÐвéѯ£¬¿ÉÒÔÆôÓøßËÙ²éѯ»º´æ¡£ÈÃÊý¾Ý¿âÒýÇæÔÚºǫ́ÇÄÇĵĴ¦ÀíÊÇÌá¸ßÐÔÄܵÄ×îÓÐЧ·½·¨Ö®Ò»¡£µ±Í¬Ò»¸ö²éѯ±»Ö´Ðжà´Îʱ£¬Èç¹û½á¹ûÊÇ´Ó»º´æÖÐÌáÈ¡£¬ÄÇÊÇÏ൱¿ìµÄ¡£
µ«Ö÷ÒªµÄÎÊÌâÊÇ£¬ËüÊÇÄÇôÈÝÒ×±»Òþ²ØÆðÀ´ÒÔÖÁÓÚÎÒÃÇ´ó¶àÊý³ÌÐòÔ±»áºöÂÔËü¡£ÔÚÓÐЩ´¦ÀíÈÎÎñÖУ¬ÎÒÃÇʵ¼ÊÉÏÊÇ¿ÉÒÔ×è ......

MysqlÓÅ»¯¼¼ÇÉ

×ܽáÁËһЩMySQLÓÅ»¯·½ÃæµÄ¼¼ÇÉ
Ò». Æô¶¯²ÎÊýÓÅ»¯
ÐÞ¸Ä my.cnf (»òÕßmy.ini)£¬¼ÓÈë/ÐÞ¸ÄÒÔϼ¸ÐÐ
#É趨»º´æµÄÁ¬½ÓÊý,½ÚÊ¡Á¬½ÓʱµÄ¿ªÏú
back_log = 64
#½ûÓÃÎļþϵͳÍⲿËø
external-locking = 0
#½ûÓÃBDB,Èç¹ûÄãȷʵ²»ÐèÒªµÄ»°,innodbÒ²ÊÇÈç´Ë
skip-bdb
#Ë÷Òý»º³å,Èç¹ûÊÇרÓõÄÊý¾Ý¿â·þÎñÆ÷,¿ÉÒÔÉèÖøߴï·þÎñÆ÷ÄÚ´ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ