如何记录共享托管 MySQL 中的慢查询?

发布于 2024-08-28 22:21:06 字数 452 浏览 1 评论 0 原文

我有一个共享主机,其中有我的网站和 MySQL 数据库。 我安装了一个用于统计的开源脚本(phpMyVisites),但它最近开始运行速度非常慢。它是使用某种框架编写的,并且有许多 PHP 文件。 我知道要查找慢查询,我可以使用 MySQL 中的慢查询日志功能。但在此共享主机上我无法使用此方法,因为我无法更改 my.cnf。我不想将我的统计脚本更改为其他脚本,也不想弄乱该脚本的所有文件来找出在哪里放置诊断代码来手动记录查询。我想在不更改 PHP 代码的情况下完成此操作。

所以我的问题是:

如何在这些情况下记录慢查询?:

  • 无法更改 my.cnf 以启用慢查询日志
  • 无法将统计脚本更改为其他
  • 不知道 scrpt 是如何编写的以及在哪里发出 mysql 命令
  • 可以不要向我的提供商询问慢速查询日志

有没有任何方法可以简单、容易、快速地做到这一点?

I have a shared hosting where I have my website and MySQL database.
I've installed a open source script for statistics (phpMyVisites) and it started to work very slow lately. It's written using some kind of framework and has many PHP files.
I know that to find slow queries I can use slow query log functionality in MySQL. But on this shared hosting I can not use this method because I can not change my.cnf. I don't want to change my statistics script to other and I don't want to mess around with all files of this script to find out where to put diagnostics code to log queries manually. I would like to do it without changes in PHP code.

So my question is:

How to log slow queries in these coditions?:

  • Can't change my.cnf to enable slow query log
  • Can't change statistics script to other
  • Don't know how scrpt is written and where mysql commands are issued
  • Can't ask my provider for slow query log

Is there any method to do this in simple, easy, fast way?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

So要识趣 2024-09-04 22:21:06

嗯,也许创建一个函数来检查 sql 查询在返回值之前花费了多长时间?然后,如果它超过指定的数量,则记录它...例如,在 php 中,我会像这样

$before = time();
//run your query
$after = time();
$difference = $after - $before
if($difference > 5000)
   //Log query

模拟 slog 查询记录器,我不认为有一种方法可以在共享托管上启用它。

希望这有帮助:)

Hmm, perhaps make a function that checks how long a sql query took before it returned a value? Then if it was over a specified amount log it... eg in php i'd do it like this

$before = time();
//run your query
$after = time();
$difference = $after - $before
if($difference > 5000)
   //Log query

That emulates the slog query logger, i dont think theres a way of enabling it on shared hosting.

Hope this helps :)

套路撩心 2024-09-04 22:21:06

我快速浏览了 phpMyVisites。在 config.inc.php 中,我发现了以下内容:

// Other
if(!defined('DEBUG')) define('DEBUG', false);
define('DEFAULT_ACTION', false);

error_reporting( E_ALL );

if(DEBUG)
{
    define('PRINT_TIME', false);
    define('PRINT_QUERY_COUNT', true);
    define('SAVE_DB_LOG', true);
    define('PRINT_QUERY', true);
} 

我怀疑 SAVE_DB_LOG 可能是一个很好的起点,所以我会尝试打开 DEBUG 模式。

I took a quick look at phpMyVisites. In config.inc.php I found the following:

// Other
if(!defined('DEBUG')) define('DEBUG', false);
define('DEFAULT_ACTION', false);

error_reporting( E_ALL );

if(DEBUG)
{
    define('PRINT_TIME', false);
    define('PRINT_QUERY_COUNT', true);
    define('SAVE_DB_LOG', true);
    define('PRINT_QUERY', true);
} 

I suspect SAVE_DB_LOG might be a good starting point, so I would try to turn DEBUG mode on.

找个人就嫁了吧 2024-09-04 22:21:06

是否将数据转储传输到本地测试系统,您可以在其中激活慢查询日志选项?

Is transferring a data dump to a local test system where you can activate the slow query log an option?

漆黑的白昼 2024-09-04 22:21:06

您可以编写一个脚本来监视 mysql processlist当你的慢速脚本运行时。

You can write a script that monitors the mysql processlist while your slow script is running.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文