alter mysqldump file before import
Posted
by julio
on Stack Overflow
See other posts from Stack Overflow
or by julio
Published on 2010-06-11T14:42:45Z
Indexed on
2010/06/11
14:52 UTC
Read the original article
Hit count: 236
Hi--
I have a mysqldump file created from an earlier version of a product that can't be imported into a new version of the product, since the db structure has changed slightly (mainly altering a column that was NOT NULL DEFAULT 0 to UNIQUE KEY DEFAULT NULL).
If I just import the old dump file, it will error out since the column that has default values of 0 now breaks the UNIQUE constraint.
It would be easy enough to either manually alter the mysqldump file, or import into a temp table and change it, then copy to the new table. However, is there a way to do this programatically, so it will be repeatable and not manual? (this will need to happen for many instances of this product).
I'm thinking something like disabling key constraints for the import, then setting all values that = 0 to NULL, then re-enabling the key constraints?
Is this possible? Any help appreciated.
© Stack Overflow or respective owner