我有一个共享主机,其中有我的网站和 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?
发布评论
评论(4)
嗯,也许创建一个函数来检查 sql 查询在返回值之前花费了多长时间?然后,如果它超过指定的数量,则记录它...例如,在 php 中,我会像这样
模拟 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
That emulates the slog query logger, i dont think theres a way of enabling it on shared hosting.
Hope this helps :)
我快速浏览了 phpMyVisites。在 config.inc.php 中,我发现了以下内容:
我怀疑 SAVE_DB_LOG 可能是一个很好的起点,所以我会尝试打开 DEBUG 模式。
I took a quick look at phpMyVisites. In config.inc.php I found the following:
I suspect SAVE_DB_LOG might be a good starting point, so I would try to turn DEBUG mode on.
是否将数据转储传输到本地测试系统,您可以在其中激活慢查询日志选项?
Is transferring a data dump to a local test system where you can activate the slow query log an option?
您可以编写一个脚本来监视 mysql processlist当你的慢速脚本运行时。
You can write a script that monitors the mysql processlist while your slow script is running.