Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

MySQL offers the ability to temporarily disable the foreign key checks, thus allowing inconsistent data to enter the database.

Is it possible to check an entire MySQL database, table by table, row by row, to ensure that all constraints are satisfied?

share|improve this question
I actually wrote a tool to do this here: – jersten Apr 30 '13 at 4:26
@JMoore interesting, I'll have a look, thanks! – Benjamin Apr 30 '13 at 10:50

Long ago I wrote a tool called oak-apply-ri. It is part of the openark-kit, which is generally well accepted. I'm beginning with the disclaimer that this tool is less popular, and I don't have much input about it (other than my own).

Nevertheless, it allows you to specify two tables that share a FK relationship, and it will verify whether the constraint holds.

You can ask it to actually resolve the differences via --action=delete or --action=setnull.

If you are suspicious, you may ask it to --print-only in which case it will not apply any changes to your database; instead it will print out the statements it would like to invoke on the database.

I'm happy to get any feedback on this.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.