Home  >  Article  >  Database  >  MYSQL速度慢的问题 记录数据库语句

MYSQL速度慢的问题 记录数据库语句

WBOY
WBOYOriginal
2016-06-07 18:07:381402browse

Web程序慢,首先的一个检测对象就是数据库,写过几年程序的都知道。现在想追踪MySQL中那些拖累服务器性能的SQL语句,怎么办

需要开启一个慢查询输出的一个机关:log_slow_queries。可以在MySQL配置文件中(my.ini/my.cnf)中设置,也可以通过MySQL客户端临时设置。第二种方法的好处是,可以不用重启MySQL服务,而使设置生效。那就来试试这个:
首先通过客户端连接到Mysql服务器,然后输入下面的语句:
SET GLOBAL log_slow_queries = ON;
SET GLOBAL long_query_time = 3;

这样MySQL就会把耗时>=3秒的SQL语句给记录下来,并输出到一个慢查询日志文件中。问题来了,这个慢查询日志文件在什么地方呢?如下,在MYSQL客户端中执行下面的语句:
show variables like 'slow_query_log_file';
就会看到MySQL慢查询日志文件位置。我的是:/usr/local/mysql/data/host-slow.log
Statement:
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