Home > Database > Mysql Tutorial > body text

mysql数据库的性能优化分析

WBOY
Release: 2016-06-07 17:51:36
Original
938 people have browsed it

本文章主要介绍关于影响到数据库性能的一些条件,大家可以参考一下本文章哦。

 影响性能的根源:

1,磁盘I/O读取

2,CPU使用率

3,资源竞争

优化的方式:

1,设计优化

2,操作优化

3,使用其他优化技术

1)设计优化:

    分类拆分数据量大的表;
    选取最适用的字段属性;
    索引设计,为经常查询用到的字段建立索引,避免查询时查找其他重复无用的数据,避免了大范围扫描;

2)操作优化:

    锁表操作;
    尽量避免子查询,将子查询转化成连接查询;
    where子句查询条件尽量少使用运算操作;
    A>2与A>=3的效果有很大的区别了,因为A>2时数据库会先找出为2的记录索引再进行比较,而A>=3时ORACLE则直接找到=3的记录索引;
    a is not null 改为 a>0 或a>''等,判断字段是否为空一般是不会应用索引的;
    a0 改为 a>0 or a

以下三条sql语句的效果是等效的:

 代码如下 复制代码

SELECT * FROM `logs` WHERE id = 1 or id = 2 or id = 3

SELECT * FROM `logs` WHERE id between 1 and 3

SELECT * FROM `logs` WHERE id in (1,2,3)

经过测试性能也是差不多,如果id是一个大数组那么最后一条书写会简单很多,可以利用

    WHERE后面的条件顺序影响 ,应该先把范围小的条件放前面,在小范围里面按接下来的条件查找;

3)其他优化技术

    使用数据缓存技术,如memcached;
    使用静态存储,对一些更新不频繁但经常调用的数据采用静态文本的存储方式;

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!