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

¸ßÐÔÄÜMySQLѧϰ±Ê¼Ç(¶þ)

 Ç°×ºË÷Òý
(1)Èç¹ûÒÔ¶à¸ö×Ö¶Î×÷ΪË÷Òý£¨a,b£¬c)×÷Ϊһ¸ökey,ÔÚ²éѯʱ·Ö¸ù¾ÝÆ¥ÅäÇé¿öÊÇ·ñʹÓÃË÷Òý£¬ËùÒÔ£¬a/ a,b/ a,b,cÕâÑùµÄ²éѯ¶¼ÄÜʹÓõ½£¬µ«ÊÇb,a/a,c/c,aµÈ²»·û֪ǰ׺ƥÅä¾Í²»ÄÜʹÓã¬ËùÒÔÔÚдsqlʱÐèҪעÒâ
(2)¶ÔÓںܳ¤µÄ×Ö·û´®ÐèÒªÉú³Ékeyʱ£¬¿ÉÒÔÕÒ³ö×ʹÓõÄ×Ö·û´®µÄ×î³£¼ûǰ׺(Ç°N¸ö×ÖÌõ×÷Ϊkey,¶ø²»Êǽ«È«¸ö×Ö·û´®×÷Ϊkey)£¬ÕâÑùÒ»·½ÃæÎþÉüÉÙÉٵľ«È·ÐÔ£¨ÓжàÓàÊý¾Ý£¬ÔÙ¹ýÂË£©£¬ÁíÒ»·½Ãæ´ó´óÌá¸ßÁ˼ìË÷ЧÂÊ£¬Í¬Ê±¼õÉÙÁËË÷ÒýµÄά»¤¿ªÏú£¨´æ´¢¿Õ¼ä£¬¸üеȣ©
ÈçÓÐ200wµÄurl,ͳ¼Æ½á¹ûÈçÏ£º
select count(*) as cnt, url from iUrl group by url order by cnt desc limit 10;
+-----+-------------------+
| cnt | url               |
+-----+-------------------+
| 380 | http://www.f.com, |
| 354 | http://www.r.com, |
| 340 | http://www.h.com, |
| 336 | http://www.u.com, |
| 336 | http://www.e.com, |
| 336 | http://www.i.com, |
| 332 | http://www.k.com, |
| 330 | http://www.t.com, |
| 330 | http://www.w.com, |
| 326 | http://www.l.com, |
+-----+-------------------+
10 rows in set (3.04 sec)
È¡Ç°N¸ö×Ö·û×÷Ϊǰ׺,ʹµÃÆ¥ÅäЧ¹ûÓëȫͳ¼Æ½Ó½üΪֹ(ÕâÀïÓÉÓÚ¶¼ÊÇÒÔhttp://www. ¿ªÍ·£¬ËùÒÔ¿´²»³öЧ¹û)
select count(*) as cnt, left(url,11) from iUrl group by url order by cnt desc limit 10;  --left(url,11) È¡×Ö·û´®µÄ×óN¸ö
Ò²¿ÉÒÔͨ¹ý¼ÆËãÈ«ÁÐÑ¡ÔñÐÔ£¬Ïêϸ·½·¨ÒªÏ¸¿´ÊéÁË
Ìí¼Óǰ׺Ë÷Òý
alter table iUrl add key ( url(11) );
ǰ׺Ë÷ÒýºÃ´¦ÊÇ£º1.¼õÉÙË÷Òý´óС 2.Ìá¸ßËٶȣ¬µ«Ò²Óв»×㣺²»ÄÜÓÃÓÚorder by/group by, ²»ÄÜ×÷Ϊ¸²¸ÇË÷Òý
¾Û¼¯Ë÷Òý
²»ÊÇÒ»ÖÖµ¥¶ÀµÄË÷Òý£¬¶øÊÇÒ»ÖÖ´æ´¢·½Ê½¡£InnoDBÖ§³Ö£¬±£´æÁËB-TreeºÍÊý¾ÝÐУ¬Ëü½«Êý¾ÝÐб£´æÔÚË÷ÒýµÄÒ¶×ÓÒ³ÖС£Ã¿¸ö±íÖ»ÓÐÒ»¸ö¾Û¼¯Ë÷Òý¡£InnoDB°´Ö÷¼ü½øÐоۼ¯¡£
¾Û¼¯Ë÷ÒýÓŵ㣺
1.¿ÉÄÜ°ÑÏà¹ØÊý¾Ý±£´æÔÚÒ»Æð
2.Êý¾Ý·ÃÎÊ¿ì
3.½áÈ«¸²¸ÇË÷Òý²éѯ¿ÉÒÔʹÓðüº¬Ò¶×Ó½ÚµãÖеÄÖ÷¼üÖµ
ȱµã£º
1.¾Û¼¯ÄÜ×î´óÏÞ¶ÈÌáÉýI/OÃܼ¯¸ºÔصÄÐÔÄÜ£¬µ«Èç¹ûÊý¾ÝÄÜ×°ÈëÄڴ棬˳Ðò¾ÍÎÞËùνÁË£¬ÕâÑù¾Û¼¯¾ÍûÓÐʲôÓô¦ÁË
2.²åÈëËÙ¶ÈÑÏÖØÒÀÀµÓÚ²åÈë˳Ðò(°´Ö÷¼ü˳Ðò²åÈëÊÇ×î¿ìµÄ)
3.¸üоۼ¯Ë÷Òý¿ªÏú´ó
4.²åÈë¡¢¸üÐÂʱ¿ÉÄܻᷢÉú·ÖÒ³£¬µ¼Ö¸ü¶àµÄ´ÅÅÌ¿Õ¼ä
5.


Ïà¹ØÎĵµ£º

mysqlµ÷Óúó

ÓÃmysql_query£¬mysql_fetch_array()ºóÓ¦¸ÃÒª
free_result().function count_admin($where = '')
{
if($where) $where = " WHERE $where";
$result = $this->db->get_one("SELECT count(*) as num from $this->table_admin_role $where");
return $result['num'];
} ......

Ò»¸ö¸´ÔÓµÄmysql²éѯÓï¾ä(case,when,then,left join )

select `a`.`id` AS `id`,`a`.`UserName` AS `UserName`,
(case when (`a`.`sRegDate` = _utf8'1990-01-01 00:00:00.0') then _utf8'' else cast(date_format(`a`.`sRegDate`,_utf8'%Y-%m-%d %H:%i:%S') as char charset utf8) end) AS `sRegDate`,(case when (`a`.`feeendtime` = _utf8'1990-01-01 00:00:00.0') then _ut ......

mysqlµ¼Èëµ¼³öÊý¾Ý¿â

¼¸¸ö³£ÓÃÓÃÀý£º
1.µ¼³öÕû¸öÊý¾Ý¿â mysqldump -u Óû§Ãû -p Êý¾Ý¿âÃû > µ¼³öµÄÎļþÃû     mysqldump -u wcnc -p smgp_apps_wcnc > wcnc.sql2.µ¼³öÒ»¸ö±í mysqldump -u Óû§Ãû -p Êý¾Ý¿âÃû ±íÃû> µ¼³öµÄÎļþÃû mysqldump -u wcnc -p smgp_apps_wcnc users> wcnc_users.sql3.µ¼³öÒ»¸öÊý¾Ý¿â½ ......

mysql sql °ÙÍò¼¶Êý¾Ý¿âÓÅ»¯·½°¸

1.¶Ô²éѯ½øÐÐÓÅ»¯£¬Ó¦¾¡Á¿±ÜÃâÈ«±íɨÃ裬Ê×ÏÈÓ¦¿¼ÂÇÔÚ where ¼° order by Éæ¼°µÄÁÐÉϽ¨Á¢Ë÷Òý¡£
2.Ó¦¾¡Á¿±ÜÃâÔÚ where ×Ó¾äÖжÔ×ֶνøÐÐ null ÖµÅжϣ¬·ñÔò½«µ¼ÖÂÒýÇæ
·ÅÆúʹÓÃË÷Òý¶ø½øÐÐÈ«±íɨÃ裬È磺
select id from t where num is null
¿ÉÒÔÔÚnumÉÏÉèÖÃ
ĬÈÏÖµ0£¬È·±£±íÖÐnumÁÐûÓÐnullÖµ£¬È»ºóÕâ
Ñù²éѯ£º
sel ......

ÓÅ»¯MySQLÊý¾Ý¿â²éѯ

ÓÅ»¯MySQLÊý¾Ý¿â²éѯ
 
   ÔÚÓÅ»¯²éѯÖУ¬Êý¾Ý¿âÓ¦ÓÃ(ÈçMySQL)¼´Òâζ×ŶԹ¤¾ßµÄ²Ù×÷ÓëʹÓá£Ê¹ÓÃË÷Òý¡¢Ê¹ÓÃEXPLAIN·ÖÎö²éѯÒÔ¼°µ÷ÕûMySQLµÄÄÚ²¿ÅäÖÿɴﵽÓÅ»¯²éѯµÄÄ¿µÄ
¡¡¡¡ÈκÎһλÊý¾Ý¿â³ÌÐòÔ±¶¼»áÓÐÕâÑùµÄÌå»á£º¸ßͨÐÅÁ¿µÄÊý¾Ý¿âÇý¶¯³ÌÐòÖУ¬Ò»ÌõÔã¸âµÄSQL²éѯÓï¾ä¿É¶ÔÕû¸öÓ¦ÓóÌÐòµÄÔËÐвúÉúÑÏÖØµÄ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ