C语言 c++ php mysql nginx linux lnmp lamp lanmp memcache redis 面试 笔记 ppt 设计模式 问题 远程连接

mysql优化相关

逆范式:1对多的时候应当尽可能的把冗余放在1那边

show status

show variables

关心以com开头的命令 show status like 'com%'

show session status like 'com_select';  //本次会话
show global status like 'com_select';    //从启动到现在

show Connections   试图连接数据库的次数

show global status like 'uptime';  服务器启动时间

________________________________________慢查询

show global status like 'slow_queries';  //查看慢查询次数,默认是十秒

show variables like 'long_query_time';//查看慢查询设置 默认10s

//设置慢查询时间(本次有效)
set long_query_time = 1;

my.ini最后增加

  log-slow-queries = D:\wamp\mysql_slow_query.log
  long_query_time=5

linux下注意写权限的问题

  show variables like '%slow%';
  执行结果会把是否开启慢查询、慢查询的秒数、慢查询日志等信息打印在屏幕上。

 SELECT SLEEP(10);//测试下慢查询

 

导入大量数据时最好禁用索引

alter table table_name  disable keys;                    alter table table_name  enable keys;

 

查看见表SQL:
show create table table_name;


对于 myisam数据库,需要定时清理
optimize table 表名

用连接代替子查询
使用join,mysql不需要在内存中国年创建临时表

如果想要 or 用到索引则,or的条件必须都加索引


在精度要求较高的项目中,用定点数来来保存,以保证准确性


查看索引的使用情况
show status like 'handler_read';

handler_read_key:  高了好
handler_read_rnd_next: 低了好

 

 

 

 

 

posted on 2012-08-31 18:17  思齐_  阅读(272)  评论(0编辑  收藏  举报