我運行MySQL 5.5.43-0 + deb8u1並試圖創建下表:MySQL的外鍵子句導致失去連接錯誤
CREATE TABLE IF NOT EXISTS `car_favorites` (
`id` INTEGER UNSIGNED auto_increment ,
`user_id` INTEGER UNSIGNED NOT NULL,
`car_id` INTEGER UNSIGNED NOT NULL,
`created_at` DATETIME NOT NULL,
`updated_at` DATETIME NOT NULL,
`deleted_at` DATETIME,
UNIQUE `user_id_car_id` (`user_id`, `car_id`),
PRIMARY KEY (`id`),
FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (`car_id`) REFERENCES `cars` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;
引用的表users
和cars
已經存在。當我嘗試運行此查詢我得到以下錯誤:
ERROR 2013 (HY000): Lost connection to MySQL server during query
之後,像做SHOW TABLES
當表中列出了,但如果我嘗試對錶(即DESCRIBE car_favorites
)服務報告執行查詢該表不存在,並重新啓動該服務使該表消失。
然而,當我刪除查詢的這個部分:
FOREIGN KEY (`car_id`) REFERENCES `cars` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
該表沒有問題產生。奇怪的是,如果我運行此查詢:
SHOW ENGINE INNODB STATUS;
立即運行後出現故障的創建查詢,也有顯示或不上市的外鍵錯誤。調高MySQL的記錄,並檢查錯誤日誌顯示這個比較模糊的錯誤:
13:21:41 UTC - mysqld got signal 11 ;
This could be because you hit a bug. It is also possible that this binary
or one of the libraries it was linked against is corrupt, improperly built,
or misconfigured. This error can also be caused by malfunctioning hardware.
We will try our best to scrape up some info that will hopefully help
diagnose the problem, but since we have already crashed,
something is definitely wrong and this may fail.
隨之而來的是堆棧跟蹤和其他一些信息,但沒有具體的。
我不知道爲什麼這個外鍵子句導致這個崩潰。任何洞察力或點在正確的方向將不勝感激。
簡短的回答:它不應該那樣做。更長的答案是,「* InnoDB:在錯誤處理期間從數據字典緩存中移除外鍵對象導致服務器退出。(錯誤#20442523)*」[在下一個版本5.5.44中修復](http:/ /dev.mysql.com/doc/relnotes/mysql/5.5/en/news-5-5-44.html)可能是罪魁禍首。這不是一個公開的bug,所以很難說,但聽起來很有說服力。 –
@ Michael-sqlbot感謝您的鏈接 – oliakaoil