Mysql

無法更改表

  • February 3, 2016

我有一個特定的表,我無法為其添加鍵:

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

Google搜尋這個問題似乎這個問題通常是配置問題或磁碟空間問題。事實上,這個數據庫執行在一個Amazon RDS實例上,這意味著它基本上是一個專用於 MySQL 的託管伺服器,具有非常標準的配置。此外,分配給我們的磁碟只有大約 25% 已滿。

考慮到虛擬機上的磁碟(我相信由 Xen 提供支持)可能已滿,而不是我分配的磁碟空間甚至可能不在同一個房間(網路儲存),我重新啟動了 RDS 實例,希望我能得到另一個 VM 上的新實例。然而,這並沒有幫助。

我的下一個故障排除步驟應該是什麼?

這是表格:

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)

嘗試修復表:

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;

建議的解決方案:

  1. 執行以下命令REPAIR TABLE table_name;
  2. 如果那(第一步)無濟於事,請嘗試將cnf文件中的臨時目錄更改為具有更大空間的新位置;
  3. 如果第一步和第二步沒有幫助,您需要將數據庫恢復到上一階段。

引用自:https://dba.stackexchange.com/questions/84607