简体   繁体   English

mysql 查询执行时间问题

[英]mysql issue with query execution time

I have a big issue on my Magento site.我的 Magento 网站上有一个大问题。

If we restart MySQL and immediately run a query on SQL (like an update from delete from etc) everything works perfectly and each query gets executed really fast (< 0.02sec).如果我们重新启动 MySQL 并立即在 SQL 上运行查询(例如从删除等中进行更新),一切都会完美运行,并且每个查询都会非常快地执行(< 0.02 秒)。

If let say Monday I restart MySQL and do queries let say Wednesday night.如果说星期一我重新启动 MySQL 并做查询让说星期三晚上。 let's say I go to PHPMyAdmin and run a query delete from select in... the query will take easy 1-2 minutes if it is completed.假设我从 go 到 PHPMyAdmin 并从 select 中运行查询删除...如果完成,查询将需要 1-2 分钟。 Normally, the site will not be accessible during the time this query is running.通常,在此查询运行期间将无法访问该站点。 The site will just load.该网站将加载。 sometimes the query gets done after 2 minutes... or sometimes MySQL will just reboot and the query will not be completed.有时查询会在 2 分钟后完成……或者有时 MySQL 会重新启动,查询不会完成。

When it reboots I get this email:当它重新启动时,我得到这个 email:

Runaway Database Queries Our system detected a lock condition in your database.数据库查询失控 我们的系统在您的数据库中检测到锁定条件。 Multiple queries were running too long.多个查询运行时间过长。 The queries were killed to maintain your site's availability.查询被终止以保持您网站的可用性。 Below is a process list of running queries for your analysis.下面是用于分析的正在运行的查询的进程列表。

But remember... the exact same query will be executed under 0.02 seconds if I do it just after I manually reboot MySQL.但请记住……如果我在手动重新启动 MySQL 之后执行此操作,将在 0.02 秒内执行完全相同的查询。

I know it is a configuration in MySQL.我知道这是 MySQL 中的配置。

I think this is related to database(storage) Engine.我认为这与数据库(存储)引擎有关。 MySQL provide different storage Engine for different purpose. MySQL 为不同的用途提供不同的存储引擎。

Ex: InnoDB: 1)table compression (read/write) 2)ACID transactions 3)row-level locking - Lock the Row until running transaction complete 4)foreign key constraints 5)automatic crash recovery例如:InnoDB:1)表压缩(读/写) 2)ACID 事务 3)行级锁定 - 锁定行直到运行事务完成 4)外键约束 5)自动崩溃恢复

MyISAM: 1)Table level locking - Lock the table until running transaction complete 2)fast to select COUNT(*)s (when WHERE, GROUP BY, or JOIN is not used) 3)full text indexing (update: supported in InnoDB from MySQL 5.6) 4)smaller disk footprint 5)very high table compression (read only) MyISAM:1)表级锁定 - 锁定表直到运行事务完成 2)快速到 select COUNT(*)s(不使用 WHERE、GROUP BY 或 JOIN 时)3)全文索引(更新:在 InnoDB 中支持MySQL 5.6) 4) 更小的磁盘占用空间 5) 非常高的表压缩(只读)

finally MyISAM is faster for reads(Select), InnoDB is faster for writes(Insert/Update).最后,MyISAM 的读取速度(选择)更快,InnoDB 的写入速度(插入/更新)更快。

Please use proper storage engine.请使用适当的存储引擎。 Hope this will resolved your issue.希望这能解决您的问题。

Please refer official document for more details.更多详情请参考官方文档。https://dev.mysql.com/doc/refman/8.0/en/storage-engines.htmlhttps://dev.mysql.com/doc/refman/8.0/en/storage-engines.html

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

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