Is there any risk in using "SET FOREIGN_KEY_CHECKS = 0"?

4

According to what I read somewhere, FOREIGN_KEY_CHECKS :

  

... Specifies whether or not to check foreign key constraints for InnoDB tables.

That is, if the guy wants to disable the foreign keys check, it does:

SET FOREIGN_KEY_CHECKS = 0;

I know it's common to use this command in case of dumps to do bank migration, backups, and the like ... But I wonder if something that can disable foreign key checking may or may not be harmful to a application.

I have the following questions:

  • In what types of scenarios would it be valid or not to use FOREIGN_KEY_CHECKS with the value 0 ?
  • FOREIGN_KEY_CHECKS is something to be considered in restricting in production environment? Is it something that may cause some kind of inconsistency in my application / database?
  • If it is possible to disable the modification in FOREIGN_KEY_CHECKS , how is the procedure?
asked by anonymous 17.11.2017 / 16:05

1 answer

2

I would not say that it would cause problems for your database, in 100% of cases, ensuring yourself that this will not lead to any future loss. I use this functionality only for recovery of backups, but never during the execution of a query by the Application, since disabling it can facilitate attacks or abnormalities in the database. But like everything else in the information, each case is a case, for example:

  • During recovery of very large backups, some servers have limited SQL execution time, keeping them disabled may be faster.

  • In some cases, the database is outdated for you to maintain, with foreign keys between fields that are not used.

24.03.2018 / 17:49