php - MySQL SET 时间戳作为慢速查询

标签 php mysql database performance

<分区>

Possible Duplicate:
How can “set timestamp” be a slow query?

我正在使用 PHP 和 MySQL 5.1 运行 Web 应用程序和 Wordpress 博客,驻留在 VPS 服务器上。慢速查询日志显示了很多不需要很长时间即可完成的条目。奇怪的是,当我点击我的博客链接时,最初加载通常需要很长时间,但之后就很快了。然后在几个小时后它又回到了缓慢的第一次点击。似乎几乎所有慢条目中都存在“SET timestamp=”查询。这是它的外观示例:

# Time: 110129  4:02:06
# User@Host: appsadmin[appsadmin] @ localhost []
# Query_time: 1.367264  Lock_time: 0.000043 Rows_sent: 18  Rows_examined: 18
use apps;
SET timestamp=1296291726;
show tables;
# Time: 110129  4:02:07
# User@Host: wp_user[wp_user] @ localhost []
# Query_time: 0.635450  Lock_time: 0.000041 Rows_sent: 11  Rows_examined: 11
use wordpress_user;
SET timestamp=1296291727;
show tables;
# Time: 110130  4:02:03
# User@Host: appsadmin[appsadmin] @ localhost []
# Query_time: 0.592159  Lock_time: 0.000000 Rows_sent: 0  Rows_examined: 0
use apps;
SET timestamp=1296378123;
SELECT /*!40001 SQL_NO_CACHE */ * FROM `mail_queue`;
# Time: 110131  4:02:08
# User@Host: appsadmin[appsadmin] @ localhost []
# Query_time: 2.789990  Lock_time: 0.000047 Rows_sent: 18  Rows_examined: 18
SET timestamp=1296464528;
show tables;
# Time: 110131  4:02:09
# User@Host: wp_user[wp_user] @ localhost []
# Query_time: 0.535981  Lock_time: 0.000041 Rows_sent: 11  Rows_examined: 11
use wordpress_user;
SET timestamp=1296464529;
show tables;
# Time: 110201  3:19:03
# User@Host: wp_user[wp_user] @ localhost []
# Query_time: 1.401393  Lock_time: 0.000071 Rows_sent: 120  Rows_examined: 145
SET timestamp=1296548343;
SELECT option_name, option_value FROM wp_options WHERE autoload = 'yes';

这表明这不是我的数据库设计问题,而是某种配置问题。

最佳答案

您是否在 VPS 上遇到交换问题?也许内存不足导致您的查询变慢。此外,我会尝试启用 mysql 查询缓存并禁用系统上不必要的东西(例如未使用的 apache 模块、系统服务等)以恢复内存。

稍微不相关,如果您的 wordpress 站点有性能问题,我会查看“WP Super Cache”(http://wordpress.org/extend/plugins/wp-super-cache/)

关于php - MySQL SET 时间戳作为慢速查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4861241/

相关文章:

php - 如何在一个数组PHP中设置子json数组

php - 将 SQL 查询设置为等于数组

mysql - 如何使用 Docker compose 修复“"Table ' Performance_schema.session_variables”不存在”?

python - python调用存储过程时字符串值不正确警告

php - 警告:mysqli::mysqli() [mysqli.mysqli]: (08004/1040): OpenCart 中的连接过多

php - 用户名输出为列表

javascript - 如何根据输入字段动态更改网页内容

php - 使用 PHP/MySQL 循环更新当前行

database - Bash 在指定行编辑文件中的最后一个字符

数据库 bool 属性或 FK 到定义表?