Category: MySql

Help and howto do things in MySQL

MySQL is the world’s most popular open source database, recognized for its speed and reliability, and is frequently used with PHP to create websites. The Electric Toolbox website uses MySQL as its database backend, and I have personally been using MySQL since 1999. In that time it has proven itself to me to be an extremely fast and reliable database management system, although the earlier versions lacked some features found in other database systems, such as stored procedures, triggers, sub selects and joined table updates. Most of these are available from the 4.1 and 5.0 releases.

If you are looking for MySQL databases – for example geographical databases, I suggest you take a look at SQL Dumpster

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.

Read More »

PHP script to export table creation SQL from MySQL

I was trying to export the structure of a MySQL database using phpMyAdmin but it kept timing out and not showing me the full create script. I think phpMyAdmin uses the information schema to get this information and its on a host with hundreds of databases and tables so querying the information schema runs very slowly. Instead I knocked together a quick PHP script to dump the structure instead and share it here.

Read More »

Master master replication with MySQL

MySQL databases can be replicated using master-slave replication and also with master-master replication. There are plenty of tutorials online showing how to do master-slave but not many showing master-master replication and the most popular one I found was a little hard to follow. Therefore I’ve written this post to show how to do master-master replication with MySQL.

Read More »

Location of MySQL’s my.cnf file

MySQL’s main configuration file is my.cnf and it is located in different locations depending on the operating system, distribution and version. This post shows how to find out where MySQL will look for the config file.

Read More »