mysql数据库sql语句优化

匿名 (未验证) 提交于 2019-12-02 22:06:11

Mysqlsql

一. 正则表达式

 

二. 查询

1. show status

这次登录以来操作多少次

Show status like ‘com_insert%’

Show status like ‘com_update%’

Show status like ‘com_select%’

Show status like ‘com_delete%’

2. show  status like 'innodb_rows%'

数据库历史操作以来增删改查的影响行数

3. show  status like 'connections%'

Mysql,,

三. Mysql

1. ,

2. ,(,)

3. like,

Like “%l”,

Like “%l%”,

4. orunion all

Or

Union all

Select * from user where name=’a’ union all select * from user where age=’20’

5. .

:Where truncate(price)=1

:where price>1 and price<2

6. ,不加索引,数字加上引号转为字符串,加索引

Where tel=12345678901 不加索引

Where tel=’12345678901’加索引

 

7. ,加索引

Select * from table where age+300>500 不加索引

Select * from table where age>500     加索引

8. ,必须要包括第一列

:

Alter table test add index(a,b,c)

不适用索引

Where b=1 and c=1

Where b=1

Where c=1

使用索引

Where a=1 b=1 c=1

Where a=1 b=1

Where a=1 c=1

Where a=1

9. is null 或者 is not null,使用时不加索引

10. (!=)不会使用索引

11. Order by 列,必须包含所有的相同的索引,才会使用索引

Order by 中,不能同时包含desc,asc

:

Alter table test add index(a,b)

Alter table test add index(c)

 

:

Select * from test where a=1 and c=1

Select * from test where b=1

Select * from test order by a asc,d desc

:

Select * from test where a=1 and b=1

Select * from test where a=1 order by b asc

Select * from test where order by a desc,b desc

Select * from test where c=1 order by c asc

12. 索引不是越多越好

select *

(join)代替子查询

,表连接>(not)exists>(not)in

,exists其次,in最差.

转载请标明出处:mysql数据库sql语句优化
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!