I\'m wondering if there is any way in mysqldump to add the appropriate create table option [IF NOT EXISTS]. Any ideas?
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
).
create a bash script with this... make sure you make it executable. (chmod 0777 dump.sh)
dump.sh
#!/bin/bash
name=$HOSTNAME
name+="-"
name+=$(date +"%Y-%m-%d.%H:%M")
name+=".sql"
echo $name;
mysqldump --replace --skip-add-drop-table --skip-comments izon -p > "$name"
sed -i 's/CREATE TABLE/CREATE TABLE IF NOT EXISTS/g' "$name"