views:

302

answers:

2

I'm wondering if there is any way in mysqldump to add the appropriate create table option [IF NOT EXISTS]. Any ideas?

+1  A: 

Not what you might want, but with --add-drop-table every CREATE is prefixed with the according DROP TABLE statement.

Otherwise, I'd go for a simple search/replace (e.g., with sed).

Boldewyn
+1  A: 

According to one source, mysqldump does not feature this option.

You could use the --force option when importing the dump file back, where MySQL will ignore the errors generated from attempts to create duplicate tables. However note that with this method, other errors would be ignored as well.

Otherwise, you can run your dump file through a script that would replace all occurrences of CREATE TABLE with CREATE TABLE IF NOT EXISTS.

Daniel Vassallo