Reputation: 2596
I am trying to drop all tables from a database, but before I drop them I need to do the following:
$MYSQL -u $MUSER -p$MPASS -h $MHOST -e "SET FOREIGN_KEY_CHECKS=0"
The above commands does not seem to work. How can I set the FK to 0 before I drop in a bash scrip?
I found out what I did wrong:
$MYSQL -u $MUSER -p$MPASS -h $MHOST -e "SET FOREIGN_KEY_CHECKS=0"
$MYSQL -u $MUSER -p$MPASS -h $MHOST -e "drop table $t"
These are two different sessions, so I did:
$MYSQL -u $MUSER -p$MPASS -h $MHOST -e "SET FOREIGN_KEY_CHECKS=0; drop table $t;"
Upvotes: 1
Views: 77
Reputation: 562348
Try running SET GLOBAL FOREIGN_KEY_CHECKS=0
. By default, the setting only affects the session where it's run -- which exits immediately.
Upvotes: 1