Skip to content

Instantly share code, notes, and snippets.

@jerryq27
Created July 5, 2018 16:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jerryq27/73ee7391dfbab7aefb3b873cc8354b2e to your computer and use it in GitHub Desktop.
Save jerryq27/73ee7391dfbab7aefb3b873cc8354b2e to your computer and use it in GitHub Desktop.
#!/bin/bash
# Original script: https://gist.github.com/togume/83b4bf40e1528742374bbce338270f34
TABLES=$(mdb-tables -1 "$1")
IFS=$'\n' # Internal Field Separator: for loops use spaces to separate input by default, this changes that default value to new lines.
for t in $TABLES
do
# Surround the names in backticks so the spaces are ignored.
echo "DROP TABLE IF EXISTS \`$t\`;"
done
# Increase the size of text fields by removing (255).
mdb-schema $1 mysql | sed -e 's/text (.[0-9]*)/text/g'
for t in $TABLES
do
# Escape ' by doubling '' and ` by doubling ``, 3rd regex removes any backslashes within quotes.
mdb-export -D '%Y-%m-%d %H:%M:%S' -I mysql $1 $t | sed -e "s/'/''/g" -e 's/"\([0-9]*\)`\([0-9]*\)"/"\1``\2"/g; s/"\([A-Z]*\)\\"/"\1"/g'
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment