Prevent users from disabling FK checks in InnoDB In MySQL, it is possible to disable FK checks using something like the following:

SET FOREIGN_KEY_CHECKS=0;


Is there a way to prevent this, i. e. preventing users from disabling foreign keys?  I don't ever want to allow that or do it myself.
You can set triggers on the relevant tables to check for foreign_key_checks=0 and signal an error if that's the case.

Call this procedure to check for the setting and signal the error:

DELIMITER $$
CREATE PROCEDURE force_foreign_key_check ()
BEGIN
    IF @FOREIGN_KEY_CHECKS = 0 THEN
        SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'foreign_key_checks is set to 0. Operation canceled.';
    END IF;
END$$
DELIMITER ;


And set your triggers like this:

CREATE TRIGGER force_foreign_key_check_insert_table1
BEFORE INSERT ON table1
FOR EACH ROW CALL force_foreign_key_check;

CREATE TRIGGER force_foreign_key_check_update_table1
BEFORE UPDATE ON table1
FOR EACH ROW CALL force_foreign_key_check;

CREATE TRIGGER force_foreign_key_check_delete_table1
BEFORE DELETE ON table1
FOR EACH ROW CALL force_foreign_key_check;