MySQL ALTER TABLE Errors – How to Resolve Issues on Amazon RDS

alter-tableamazon-rdserrorsMySQL

I have a particular table that I cannot add a key for:

mysql> ALTER TABLE tasks ADD KEY `fruitful_user_count` (`user_id`, `is_fruitful`);
ERROR 1034 (HY000): Incorrect key file for table 'tasks'; try to repair it

Googling the issue it seems that this problem is often either a configuration issue or a disk space issue. In fact, this database is running on an Amazon RDS instance, which means that it is basically a managed server dedicated to MySQL with a very standard configuration. Also, the disk allocated to us is only about 25% full.

Considering that perhaps there disk on the VM (powered by Xen I believe) is full, and not my allocated disk space which is likely not even in the same room (network storage), I rebooted the RDS instance in the hope that I would get a new instance on another VM. However, that did not help.

What should be my next troubleshooting step?

This is the table:

mysql> show create table tasks;
+-------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
+-------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tasks | CREATE TABLE `tasks` (
`user_id` char(32) NOT NULL,
`module_id` int(11) NOT NULL DEFAULT '0',
`is_successful` tinyint(1) DEFAULT NULL,
`is_fruitful` tinyint(1) DEFAULT NULL,
`last_run` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`last_pulled` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (`user_id`,`module_id`),
KEY `phone_scrapes_user` (`user_id`),
KEY `phone_scrapes_module` (`module_id`),
KEY `urgency` (`last_pulled`,`last_run`),
KEY `successful_user_count` (`user_id`,`is_successful`),
KEY `is_successful` (`is_successful`),
KEY `fruitness` (`is_fruitful`,`is_successful`),
CONSTRAINT `tasks_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`),
CONSTRAINT `tasks_ibfk_2` FOREIGN KEY (`module_id`) REFERENCES `modules` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
+-------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.01 sec)

Best Answer

Try to repair the table:

mysql> LOCK TABLES `fruitful_user_count` WRITE;
mysql> CREATE TABLE `fruitful_user_count_new` LIKE `fruitful_user_count`;
mysql> INSERT INTO `fruitful_user_count_new` SELECT * FROM `fruitful_user_count`;
mysql> RENAME TABLE `fruitful_user_count` TO `fruitful_user_count_old`;
mysql> RENAME TABLE `fruitful_user_count_new` TO `fruitful_user_count`;
mysql> UNLOCK TABLES;