5

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?

1
  • @JMoore interesting, I'll have a look, thanks!
    – BenMorel
    Apr 30, 2013 at 10:50

1 Answer 1

2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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