¸ømysqlÊý¾Ý±í¼ÓË÷ÒýµÄÒ»´Î¾ÑéÓëÌå»á.
×òÌìÓöµ½Ò»¸öÎÊÌâ:
ÔÚÒ»ÕÅÓÐÈýÊ®ÍòÌõ¼Í¼µÄÊý¾Ý±íA£¬ÆäÖ÷¼ü×ÔÔö×Ö¶Îid£¬name×ֶΣ¨varchar)£¬»¹ÓÐtype_id£¨int)£¬ÔÚname×Ö¶ÎÉÏÒѾÌí¼ÓÁËË÷Òý¡£type_idÓÉÓÚÊÇÕûÐÍ×ֶΣ¬ÈÏΪ¼ÓË÷ÒýûÓÐÌ«¶àµÄÒâÒ壬ËùÒÔûÓмÓË÷Òý¡£
±¾´ÎÓÐÒ»¸öÐèÇóÊÇÔÚÒ»¸öÑ»·Öа´type_id²éѯ´Ë±íA£¬½á¹ûÒ»Ö´ÐдËÑ»·£¬mySQLÁ¢¿ÌÕ¼ÓÃCPUµ½200%ÒÔÉÏ£¬µ¼Ö·þÎñÆ÷ÏìÓ¦¼«Âý¡£
¿ªÊ¼Ã»Ïëµ½ÊDzéѯËٶȵÄÎÊÌ⣬ºóÀ´·¢ÏÖ»»Ò»¸ö±í£¬CPUÕ¼ÓÃÂÊÁ¢¿ÌϽµ¡£ÓÚÊÇ·ÖÎöÁ˲éѯ¹ýѯ£¬·¢ÏÖÿ´Î²éѯ¶¼Òª±éÀúÕû±í£¬ËùÒÔÊý¾Ý¿âѹÁ¦·Ç³£´ó¡£ÊÖ¹¤Ö±½ÓʹÓÃsqlÔÚÊý¾Ý¿â²éѯ£º
select * from A where type_id = xxxx
Ö´ÐÐʱ¼äԼΪ0.42s(400ms×óÓÒ£©£¬ËٶȽÏÂý¡£
ÓÚÊÇÔÚtype_idÉÏÌí¼ÓË÷Òý£¬È»ºóÔÙÖ´ÐÐͬÌõÓï¾ä¡£
Ö´ÐÐʱ¼äΪ0.01s(10ms×óÓÒ£©£¬ËÙ¶ÈÃ÷ÏÔÌáÉý£¨40±¶×óÓÒ£©¡£
ÔÙÖ´ÐÐÑ»·£¬·¢ÏÖCPUÕ¼ÓÃ8%×óÓÒ£¬±È½ÏÀíÏë¡£
ÐÔÄÜÌáÉýµÄÔÒò·ÖÎö£º
type_idµÄÖµÓÐÌØÊâÐÔ£º´ó²¿·Ötype_idµÄֵΪ0£¬Ë÷ÒýЧ¹ûÃ÷ÏÔ¡£ÕýºÃ±¾´Î²éѯ²»ÐèÒª²éѯtype_idΪ0µÄ¼Í¼¡£Èç¹ûÒª²éѯtype_idΪ0µÄ¼Í¼£¬ÔòЧ¹ûÌáÉý¿ÉÄܲ»Ã÷ÏÔ¡£
Ìå»á£º
£¨1£©ÔÚÓöµ½²éѯÐÔÄܵÄʱºò£¬Êʵ±µÄ·ÖÎöÊý¾Ý£¬Ìí¼ÓË÷Òý£¬¿ÉÄÜÄÜ´ó·ùÌá¸ßÐÔÄÜ¡£
£¨2£©ÊÇ·ñÌí¼ÓË÷Òý£¬ÐèÒª¿¼Á¿Êý¾Ý×ÜÁ¿¼°Êý¾Ý¸üÐÂƵ¶ÈÔÙ×ö¾ö¶¨¡£
£¨3£©·ÖÎöÒ»ÌõÓï¾äÊÇ·ñʹÓÃÁËË÷Òý¡£¿ÉʹÓà explain sql;
Èçexplain select * from A where type_id = xxxx »áÏÔʾÊÇ·ñʹÓÃË÷Òý¡£
Ïà¹ØÎĵµ£º
Íü¼ÇMySQL(ºÍPHP´îÅäÖ®×î¼Ñ×éºÏ)
ROOTÃÜÂëÊÇÔÚMySQL(ºÍPHP´îÅäÖ®×î¼Ñ×éºÏ)ʹÓÃÖкܳ£¼ûµÄÎÊÌ⣬¿ÉÊÇÓкܶàÅóÓѲ¢²»»áÖØÖÃROOTÃÜÂ룬Äǽпడ£¬ÎÒÓÐÉîÓид¥£¬ÌØд´ËÎÄÕÂÓë´ó¼Ò½»Á÷£º
1¡¢±à¼MySQL(ºÍPHP´îÅäÖ®×î¼Ñ×éºÏ)ÅäÖÃÎļþ£º
windows»·¾³ÖУº%MySQL(ºÍPHP´îÅäÖ®×î¼Ñ×éºÏ)_installdir%\my.ini¡¡//Ò»°ã ......
##/etc/my.cnf:
# [mysql]
# default-character-set=utf8
# [mysqld]
# character-set-server=utf8
# collation-server=utf8_general_ci
# [client]
# default-character-set=utf8
/etc/init.d/mysqld stop
/etc/init.d/mysqld start
# dump db
mysqldump -u dbuser -pdbpass --opt --skip-set-charset --defaul ......
ÔÚMySQL 3.23.44°æ±¾ºó£¬InnoDBÒýÇæÀàÐ͵ıíÖ§³ÖÁËÍâ¼üÔ¼Êø¡£
Íâ¼üµÄʹÓÃÌõ¼þ£º
1.Á½¸ö±í±ØÐëÊÇ
InnoDB±í£¬MyISAM±íÔÝʱ²»Ö§³ÖÍâ¼ü£¨¾Ý˵ÒÔºóµÄ°æ±¾ÓпÉÄÜÖ§³Ö£¬µ«ÖÁÉÙÄ¿Ç°²»Ö§³Ö£©£»
2.Íâ¼üÁбØÐ뽨Á¢ÁËË÷Òý£¬MySQL
4.1.2ÒÔºóµÄ°æ±¾ÔÚ½¨Á¢Íâ¼üʱ»á×Ô¶¯´´½¨Ë÷Òý£¬µ«Èç¹ûÔÚ½ÏÔçµÄ°æ±¾ÔòÐèÒªÏÔʾ½¨Á¢£»
3.Íâ¼ü¹Øϵµ ......
using System;
using System.Data;
using System.Diagnostics;
using System.Collections.Generic;
using MySql.Data.MySqlClient;
namespace System
{
/// <summary>
/// Description of MySqlDBUtil.
/// </summary>
public class MySqlDBUtil
{
&nbs ......
²éѯÖظ´¼Ç¼ select * from table GROUP BY name
Ö»°ÑÓÐÖظ´µÄÏÔʾ³öÀ´
select * ,count(*) as nums from tab_a group by name having nums>1
·½·¨Ò»£º£¨Õâ¸ö·½·¨±È½Ï²»´í£¬Ö»ÊÇ×ÔÔö×ֶλáÖؽ¨£©
н¨Ò»¸öÁÙʱ±í
create table tmp as select * &nb ......