简体   繁体   English

在Mysql中更改表的存储引擎

[英]Changing storage engine of table in Mysql

Currently the storage type of table is innodb , i want to add full text search on the table which is only possible on MYISAM engine. 目前表的存储类型是innodb,我想在表上添加全文搜索,这只能在MYISAM引擎上进行。 I tried using the command => alter table film engine = myisam; 我尝试使用命令=> alter table film engine = myisam; and got the error: 并得到错误:

1217 - Cannot delete or update a parent row: a foreign key constraint fails

Help Please!! 请帮助!! Thanks. 谢谢。

You must find the tables in the database that refer to this table through a FK constraint: 您必须通过FK约束在数据库中找到引用此表的表:

Identify the foreign key constraints for the table. 确定表的外键约束。 Either use 要么使用

SHOW CREATE TABLE `table_in_db_film`\G;

or 要么

USE db_of_film_table;
SHOW TABLE STATUS LIKE 'film'\G

afterwards execute the necessary statements 然后执行必要的陈述

ALTER TABLE film DROP FOREIGN KEY `ibfk_something`;

until you drop all constraints (of course replace ibfk_something with your constraint names). 直到你放弃所有约束(当然用你的约束名称替换ibfk_something )。 After this you should be able to alter the table engine. 在此之后,您应该能够更改表引擎。

You can't change the table's engine to MyISAM without removing the Foreign Key constraints and thus losing integrity. 您不能在不删除外键约束的情况下将表的引擎更改为MyISAM,从而失去完整性。

It would be better to use both engines, MyISAM and InnoDB. 最好使用两个引擎,MyISAM和InnoDB。 Keep all data in InnoDB and duplicate the table (or just the columns you want to be full-text searching) in MyISAM. 将所有数据保存在InnoDB中,并在MyISAM中复制表格(或者只是要进行全文搜索的列)。 This will need some mechanism (triggers) for the data duplication to be automated. 这将需要一些机制(触发器)来自动化数据复制。

Other options here: MySQL storage engine dilemma 其他选项: MySQL存储引擎困境

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM