简体   繁体   中英

mysql issue with query execution time

I have a big issue on my Magento site.

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).

If let say Monday I restart MySQL and do queries let say Wednesday night. 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. 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.

When it reboots I get this 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.

I know it is a configuration in MySQL.

I think this is related to database(storage) Engine. MySQL provide different storage Engine for different purpose.

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

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)

finally MyISAM is faster for reads(Select), InnoDB is faster for writes(Insert/Update).

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.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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