Platinum Partner

Mysql Importing Without Dropping Tables

// Had to import a lot of .sql backups into one server.  Unfortunately they included a lot of DROP TABLE statements which constantly hosed my data. Here I have skewered sed to delete those sql statements before importing.


# Create a temporary filename
uniq="/tmp/temp_"`date "+%s"`

for item in `ssh user@dbserver ls`;
do
     echo -n "Importing $item..."
     scp user@dbserver\:$item $uniq;
     gunzip < $uniq | sed {/$'DROP TABLE IF EXISTS'/d} | mysql -f -u root $DB_SCHEMA_NAME
     echo "..done"
done

# clean up
rm -f "$uniq"
{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}