MySQL知识大搜索

来源:互联网 发布:工业企业数据库2015 编辑:程序博客网 时间:2024/06/05 15:38

MySQL优化细节:

1.适当使用索引
2.避免like等正则表达式的使用。如将:

select id from table where id like98___”//替换为:select id from table where id > 9800

3.将大表拆分为小表,减小表的列数
4.使用join,而不是嵌套or笛卡儿积
5.拆分delete。因为一个大的delete可能要很久,由于DB内部的锁机制,会使DB几十秒内无法响应,于是使用分批的方式,用limit限制每次delete的个数。

mysql_query("delete * from student where age <= 20");//替换为:while(1) {    mysql_query("delete * from student where age >= 20 limit 1000");    if (mysql_affected_rows() == 0)        break;    sleep(50);}

6.少使用select *,用什么就选什么
7.使用临时表。当同一个SQL查询要使用多次时,建立一个临时表用来存储结果。

select * from student left join courseINTO TEMP temp_table//这样我们再使用这个查询时,可以:select * from temp_table

8.大数据分页查询
search(vtype, id)建立复合索引,第一位的是where判断的索引,第二位是主键,如:

//设置复合索引search(vtype, id)//分页查询,从第90000条开始的10个记录select id from collect where vtype=1 limit 90000,10; 

MySQL语句:
http://blog.csdn.net/u011225629/article/details/46698969

MySQL线程池:
http://blog.csdn.net/u011225629/article/details/46721907

MySQL索引详解:
http://blog.csdn.net/u011225629/article/details/46754071

MySQL索引优化:
http://blog.csdn.net/u011225629/article/details/46754093

MySQL大数据建表优化:
http://blog.csdn.net/u011225629/article/details/46775621

MySQL大数据查询优化:
http://blog.csdn.net/u011225629/article/details/46775727

MySQL大数据分页查询优化:
http://blog.csdn.net/u011225629/article/details/46775815

2 0
原创粉丝点击