I needed to do the same, so I ended up writing a stored procedure to do the job. I have included it here and it works great on MySQL Workbench. Interestingly, it will not work correctly in Navicat, since the original select statement will not skip NULL values โโand, therefore, will delete all your indexes.
I recommend that you read the code and break a few things and run them separately so that you are sure that it will do what you want.
As it is written, it should delete every foreign key in all your databases in this connection. Do not run it as it is, if that is not what you want to do.
Use at your own risk.
DELIMITER $$ CREATE PROCEDURE `pRemoveAllForeignKeys`() BEGIN DECLARE sName TEXT; DECLARE cName TEXT; DECLARE tName TEXT; DECLARE done INT DEFAULT 0; DECLARE cur CURSOR FOR SELECT TABLE_SCHEMA, CONSTRAINT_NAME, TABLE_NAME FROM information_schema.key_column_usage WHERE REFERENCED_TABLE_SCHEMA IS NOT NULL
source share