MySQL “Incorrect key file for table” error

When saving a record to a MySQL table the other day I got the error message “Incorrect key file for table ‘mytable’; try to repair it”. I am uncertain why the error occured and how to ensure it doesn’t happen again in the future but a quick fix for the time being is simple.

How to repair a MySQL table

All you need to do is to repair the table by running the following SQL command, where “mytable” is the name of the table that gave the error:

REPAIR TABLE `mytable`;
 

You can run this from e.g. the MySQL CLI or phpMyAdmin. From phpMyAdmin select the table, then “Operations” from the navigation tabs in the right frame above the table info; then “Repair Table” from the “Table maintenance” options at the bottom of the page.

When the table is /tmp/#sql_xxx_x.MYI

If the error looks like “Incorrect key file for table ‘/tmp/#sql_xxx_x.MYI’; try to repair it” where it refers to a temporary location on the filesystem, it’s likely you’ve run out of diskspace. Read my follow up post for more information.

Prefix img src assets with a leading slash in SilverStripe

When inserting an image into the TinyMCE HTML editor in SilverStripe it doesn’t prefix the src attribute of the img tag with a leading slash leaving it like e.g. src="assets/images/myimage.jpg". This is acceptable because it writes out a <base> tag into the document <head> so these relative urls are made into absolute URLs using the href in the base tag. However, as I have found, some bots ignore the base tag and are unable to grab the images correctly. This post shows how to modify your base page class in SilverStripe to prefix assets with a leading slash.

Style the HTML hr tag with CSS

In the past I’ve fallen into the trap of creating a special class for rendering lines or separators in an HTML document and assigning the class to a div, ending up with something like <div class="line"></div> or something along those lines. Not only is this not semantic, it’s a whole bunch of extra unecessary HTML code which can be simplified by styling and using the often forgotten <hr> tag.

Testing if a PHP include file was included

PHP’s include() and include_once() functions can return values to the calling script which can be useful for testing to see if the file was actually included, for example if a configuration file whose filename is based on the website’s domain name was included. If no return value is set then it will return integer 1 if included, or boolean false if not.

Categories PHP