Tag Archives: 优化

MySQL的基本优化

1、查询执行速度慢的sql语句

  • 查看当前“慢语句”标准:show variables like ‘%long%’
    mysql> show variables like '%long_query_time%';
    +-----------------+----------+
    | Variable_name   | Value    |
    +-----------------+----------+
    | long_query_time | 10.00000 |
    +-----------------+----------+
    1 row in set (0.00 sec)
    
    mysql> show variables like '%slow%';
    +---------------------------+--------------------------------+
    | Variable_name             | Value                          |
    +---------------------------+--------------------------------+
    | log_slow_admin_statements | OFF                            |
    | log_slow_slave_statements | OFF                            |
    | slow_launch_time          | 2                              |
    | slow_query_log            | ON                             |
    | slow_query_log_file       | /var/lib/mysql/ubuntu-slow.log |
    +---------------------------+--------------------------------+
    5 rows in set (0.00 sec)
    
  • 开启日志:set global slow_query_log = on;
  • 修改时间标准:set long_query_time = 0.5;
  • slow_query_log_file为日志文件所在路径;
  • 查看日志
    [……]

    继续阅读