debugging一个mysql连接

我想弄清楚如何诊断一个MySQL连接问题。

  • 当我在本地机器上运行一组查询时,大概需要1秒钟的时间。
  • 当我在具有RDS支持的mysql实例的AWS计算机上运行同一组查询时,大约需要8倍的时间才能运行。 这些机器的尺寸大致相当。

这里有两个问题:

  • 我将如何去诊断问题是什么? 这不是查询或数据库,因为它们在两种情况下都是相同的。 例如,我可以使用哪些工具或命令来查明可能的问题?
  • 有什么方法可以加快从ec2服务器到rds服务器的连接? 我的印象是,rds-backed实例在速度上(如果不是更快)比在服务器上有相同的速度。

你应该使用分析。

set profiling=1;

然后在同一个会话中进行查询。 然后查找configuration文件:

show profiles;

并显示它们:

show profile for query X; ,其中X – 是一些configuration文件。

 mysql> show profile for query 2; +--------------------------------+----------+ | Status | Duration | +--------------------------------+----------+ | starting | 0.000042 | | Waiting for query cache lock | 0.000011 | | init | 0.000008 | | checking query cache for query | 0.000081 | | checking permissions | 0.000017 | | Opening tables | 0.000143 | | init | 0.000038 | | System lock | 0.000021 | | optimizing | 0.000020 | | executing | 0.000021 | | end | 0.000013 | | query end | 0.000010 | | closing tables | 0.000027 | | freeing items | 0.000082 | | cleaning up | 0.000198 | +--------------------------------+----------+ 15 rows in set, 1 warning (0.00 sec)