MySQL表创建异常缓慢


10

在我的一个MySQL数据库上创建一个简单的表需要花费很多时间:

mysql> CREATE TABLE blah (id BIGINT UNSIGNED NOT NULL PRIMARY KEY);
Query OK, 0 rows affected (16.58 sec)

机器很空闲:

01:21:26 PM       CPU     %user     %nice   %system   %iowait    %steal     %idle
01:21:27 PM       all      0.50      0.00      0.21      0.00      0.00     99.29

任何想法如何对此进行调查?

编辑:按照DTest的建议,这是执行配置文件:

mysql> SHOW PROFILE FOR QUERY 1;
+----------------------+----------+
| Status               | Duration |
+----------------------+----------+
| starting             | 0.000044 |
| checking permissions | 0.000024 |
| creating table       | 8.668129 |
| After create         | 0.000014 |
| query end            | 0.000005 |
| freeing items        | 0.000028 |
| logging slow query   | 0.000004 |
| logging slow query   | 0.000206 |
| cleaning up          | 0.000006 |
+----------------------+----------+

@Phil具有大约16GB内存的物理机。
亚当·马坦

@Phil这是具有许多MySQL操作的生产服务器,因此磁盘不应处于空闲状态。
亚当·马坦

Answers:


10

我将启用概要分析,以了解需要花费这么长时间的事情。使用mysql CLI的示例:

SET profiling = 1;
CREATE TABLE blah (id BIGINT UNSIGNED NOT NULL PRIMARY KEY);
SET profiling = 1;

您应该得到如下响应:

mysql> SHOW PROFILES;
| Query_ID | Duration   | Query |
+----------+------------+-------------------------------------------------------------+
|        1 | 0.00913800 | CREATE TABLE blah (id BIGINT UNSIGNED NOT NULL PRIMARY KEY) |
+----------+------------+-------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> SHOW PROFILE FOR QUERY 1;
+----------------------+----------+
| Status               | Duration |
+----------------------+----------+
| starting             | 0.000071 |
| checking permissions | 0.000007 |
| Opening tables       | 0.001698 |
| System lock          | 0.000043 |
| creating table       | 0.007260 |
| After create         | 0.000004 |
| query end            | 0.000004 |
| closing tables       | 0.000015 |
| freeing items        | 0.000031 |
| logging slow query   | 0.000002 |
| cleaning up          | 0.000003 |
+----------------------+----------+
11 rows in set (0.00 sec)

1
@AdamMatan不确定是否阅读了性能分析文档,但是还有其他一些标志用于显示查询的配置文件CPUBLOCK IO等等在“创建表”阶段可能会帮助您。
德里克·唐尼
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.