简体   繁体   English

有什么方法可以减少由于运行查询而在mysql中使用的资源量?

[英]What are some ways to reduce the amount of resources being used in mysql from queries being ran?

My site is running fine but anytime I try to make changes to the database it moves extremely slow and sometimes freezes up. 我的网站运行良好,但是任何时候我尝试对数据库进行更改时,它的运行速度都会非常缓慢,有时会冻结。 This being due to the load being too high from too many queries being ran, I've already reduced the number of queries yet my websites traffic keeps increasing and continuing to cause mysql to run slow. 这是由于运行过多查询导致负载过高,我已经减少了查询数量,但我的网站流量却不断增加,并继续导致mysql运行缓慢。 My admins have optimized mysql already so I'm looking for alternative methods to improve the performance of the database and decrease the load without running fewer queries. 我的管理员已经对mysql进行了优化,因此我正在寻找其他方法来提高数据库性能并减少负载,而无需运行更少的查询。

If the DB itself is tweaked as far as it can go, you've got two other options: 如果对数据库本身进行了尽可能多的调整,则还有另外两个选择:

  1. Upgrade hardware (faster disks, faster cpu, more ram) 升级硬件(更快的磁盘,更快的cpu,更多的ram)
  2. Set up a cluster of db servers so the load gets split amongst multiple machines. 设置数据库服务器集群,以便在多台计算机之间分配负载。

Apart from upgrading the server hardware or installing new servers, I would look into a query profiler such as the built in MySQL one or Jet Profiler which also comes highly recommended. 除了升级服务器硬件或安装新服务器外,我还将研究查询分析器,例如内置的MySQL oneJet Profiler ,也强烈建议使用它。 This will help you identify bottlenecks in your queries. 这将帮助您确定查询中的瓶颈。

Also, if a bottleneck is encountered, you may need to refactor your code in order to run less queries or make better use of table indices. 另外,如果遇到瓶颈,则可能需要重构代码,以运行更少的查询或更好地利用表索引。

However, if your budget permits, @Marc's answer is definitely recommended. 但是,如果您的预算允许,绝对建议使用@Marc的答案。

Is it possible to further optimize your queries or schema? 是否可以进一步优化查询或架构?

I've found mysql's slow query log useful to identify which queries to profile and improve http://dev.mysql.com/doc/refman/5.0/en/slow-query-log.html 我发现mysql的慢速查询日志对于确定哪些查询进行概要分析和改进http://dev.mysql.com/doc/refman/5.0/en/slow-query-log.html很有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM