如何在服务器上启用MySQL慢查询日志? [英] How can I enable MySQL slow query log on my server?

查看:294
本文介绍了如何在服务器上启用MySQL慢查询日志?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在服务器上启用慢速查询日志?我通过在my.ini文件中添加log-slow-queries =[path]在本地主机上启用了它,但是不知道如何在服务器上添加它.我的服务器是基于Linux的,并且具有PHP 5.2.16版.

How do I enable slow query log on my server? I have enabled it on my local host by adding log-slow-queries =[path] in my.ini file, but don't know how to add this on my server. My server is Linux-based and has PHP version 5.2.16.

推荐答案

启用慢速查询日志与PHP版本无关.您必须在MySQL服务器中启用它.您可以通过两种方式启用

Enabling slow query log has nothing to do with PHP version. You have to enable it in the MySQL server. You can enable in two ways

  1. 在运行时
  2. 服务器启动期间

如果服务器高于5.1.6,则可以在运行时本身中设置慢速查询日志.您必须对其执行此查询.

If your server is above 5.1.6 you can set the slow query log in the runtime itself. For which you have to execute this queries.

set global log_slow_queries = 1;
set global slow_query_log_file = <some file name>;

或者,您也可以在my.cnf/my.ini选项文件中设置此选项

Or alternatively you can set the this options in the my.cnf/my.ini option files

log_slow_queries = 1; 
slow_query_log_file = <some file name>;

更改了选项文件后,需要重新启动MySQL服务器.

Where the option file is changed, the MySQL server need to be restarted.

可以在此处找到mysql选项文件的位置 http ://dev.mysql.com/doc/refman/4.1/en/mysql-config-wizard-file-location.html

Location of the mysql option file can be found here http://dev.mysql.com/doc/refman/4.1/en/mysql-config-wizard-file-location.html

FYI:log_slow_queries在MySQL 5.6.1中已删除,而使用了slow_query_log. http://dev.mysql.com/doc/refman/5.6/zh-CN/server-options.html#option_mysqld_log-slow-queries

FYI : log_slow_queries was removed in MySQL 5.6.1 and slow_query_log is used instead. http://dev.mysql.com/doc/refman/5.6/en/server-options.html#option_mysqld_log-slow-queries

但是为了提高性能,您可以将日志输出(选项log_output)设置为TABLE. 另外,您还可以查看其他慢速查询日志选项,例如long_query_timelog-queries-not-using-indexes

But for performance you can set the log output (option log_output) to TABLE. Also you can have a look other slow query log options like long_query_time, log-queries-not-using-indexes

这篇关于如何在服务器上启用MySQL慢查询日志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆