PHP 网页正在调用待处理的 AJAX 脚本(查询数据库)。 我不得不停止它,因为它是 2 小时前调用的。 而我在另一台 DigitalOcean 服务器上测试它,它在 2 分钟内响应。
服务器相似(16GB RAM、8CPU 等)
而且流量并不多。
我真的不明白。我注意到的唯一区别是服务器:MySQL 版本和 Ubuntu 版本。
第一台服务器:MySQL 服务器版本:5.5.52-0ubuntu0.14.04.1 (Ubuntu 14.04.2 LTS)。
第二个:MySQL 服务器版本:5.7.13-0ubuntu0.16.04.2 (Ubuntu 16.04 LTS)。
这些表在所查询的相同表上具有相同的索引。
但是我还是不明白问题出在哪里?
也许来自 SQL 查询:
SELECT COUNT(*) as max_tok FROM dest WHERE b_id = 1 and statut < 3 and id IN (SELECT dest_id from ouv where created_at > '2016-07-13 00:00:00' and created_at < '2016-10-13 00:00:00')
MySQL 服务器 1:
+---------------+------------+----------------------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+---------------+------------+----------------------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| dest | 0 | PRIMARY | 1 | id | A | 5994930 | NULL | NULL | | BTREE | | |
| dest | 0 | dest_b_id_mail_index | 1 | b_id | A | 16 | NULL | NULL | | BTREE | | |
| dest | 0 | dest_b_id_mail_index | 2 | mail | A | 5994930 | NULL | NULL | | BTREE | | |
| dest | 1 | dest_statut_index | 1 | statut | A | 16 | NULL | NULL | | BTREE | | |
| dest | 1 | dest_base_id_hash_index | 1 | b_id | A | 16 | NULL | NULL | | BTREE | | |
| dest | 1 | dest_base_id_hash_index | 2 | hash | A | 5994930 | NULL | NULL | | BTREE | | |
+---------------+------------+----------------------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
MySQL 服务器 2:
+---------------+------------+----------------------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+---------------+------------+----------------------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| dest | 0 | PRIMARY | 1 | id | A | 4320721 | NULL | NULL | | BTREE | | |
| dest | 0 | dest_b_id_mail_index | 1 | b_id | A | 1156 | NULL | NULL | | BTREE | | |
| dest| 0 | dest_b_id_mail_index | 2 | mail | A | 4320721 | NULL | NULL | | BTREE | | |
| dest | 1 | dest_statut_index | 1 | statut | A | 3 | NULL | NULL | | BTREE | | |
| dest | 1 | dest_b_id_hash_index | 1 | b_id | A | 942 | NULL | NULL | | BTREE | | |
| dest | 1 | dest_b_id_hash_index | 2 | hash | A | 4320721 | NULL | NULL | | BTREE | | |
+---------------+------------+----------------------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
(P.S.:SQL 查询在我们的第二台服务器上运行)
最佳答案
在这种特殊情况下,我已迁移到新的 DO 服务器(MySQL 5.7.15 和 PHP 7.0.12)。 我已经备份了数据库和文件并将其导入到新服务器中。
关于php - Ajax mysql 查询部分工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40022743/