Updated: September 16th, 2012
I've had MySQL on my Windows 7 laptop for a bit (as part of wampserver), mostly for local offline WordPress development.
However, even though MySQL is relatively stable, I've been observing a vast quantity of intermittent MySQL errors, as reported by WordPress in the PHP error log (C:\wamp\logs\php_error.log). Here are some examples:
[05-Jan-2010 09:47:51] WordPress database error Error on delete of 'C:\Windows\TEMP\#sql17e0_1a2_6.MYD' (Errcode: 13) for query SELECT t.*, tt.* FROM wp_terms AS t INNER JOIN wp_term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN wp_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ('category') AND tr.object_id IN (3) ORDER BY t.name ASC made by require, require_once, include, get_footer, locate_template, load_template, require_once, dynamic_sidebar, call_user_func_array, widget_rrm_recent_posts, RecentPosts->execute, ppl_expand_template, otf_categorylinks, get_the_category, wp_get_object_terms [05-Jan-2010 09:50:42] WordPress database error Error on delete of 'C:\Windows\TEMP\#sql17e0_1b0_0.MYD' (Errcode: 13) for query SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_posts INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) INNER JOIN wp_term_taxonomy ON (wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id) WHERE 1=1 AND wp_term_taxonomy.taxonomy = 'category' AND wp_term_taxonomy.term_id IN ('3') AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 10 made by require, wp, WP->main, WP->query_posts, WP_Query->query, WP_Query->get_posts
The important part here is "Errcode: 13", which is a file access error. The MySQL daemon process (mysqld.exe) randomly cannot access temporary tables it itself creates, which causes these errors and failed queries.
After looking around and finding nothing obvious, I tracked down a few forum posts mentioning the same issue.
Here is the gist – the problem is caused by an anti-virus program that is clearly not working properly.
The one mentioned on the forums is McAfee (big surprise, right? McAfee is a piece of junk – probably the worst anti-virus I've ever tried). In my case, however, it was the recently installed freeware security program from Microsoft called Microsoft Security Essentials, highly praised but problematic in this case nonetheless.
After thinking about it, I am confident that these security programs don't actually purposely prohibit access to the files MySQL creates. Instead, they lock these files for the duration of the check, so that the system doesn't get infected before they are approved. If you notice, the problems are related to temporary tables, created by MySQL on the fly. MySQL probably has a very short access timeout for these files, for performance reasons, and because it doesn't get this access fast enough, it considers it a failure (file deletions are failing, as you can see in the log).
Now onto fixing the problem. The solution is to have Microsoft Security Essentials, in my case, or whatever your security program may be ignore these files.
You can block the whole Temp directory from being checked. It is not a good idea, as viruses can trickle down to that location and bypass your anti-virus:
Instead, you should just ignore by file extension: *.MYI and *.MYD. MySQL uses files with these extensions for its MyISAM table types. Using this approach is obviously safer as it doesn't single out a directory and instead targets specific files:
After I applied either of these exclusions, all MySQL Error 13 problems went away immediately.
The intermittent Error 13 problem on Windows is caused by 2 otherwise legitimate processes which, when mixed together, end up breaking MySQL.
Is this entirely the fault of the antivirus programs? Inadvertently, perhaps so.
Could MySQL be a bit smarter in this scenario? Perhaps so as well.
What do you, MySQL pros, think?
In the meantime, if you found this article useful, feel free to buy me a cup of coffee below.