Skip to content

Instantly share code, notes, and snippets.

@mythmon
Created August 9, 2013 17:23
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mythmon/6195419 to your computer and use it in GitHub Desktop.
Save mythmon/6195419 to your computer and use it in GitHub Desktop.
This is the script I use to set import a large database dump. It goes faster than simply piping into mysql.
#!/bin/bash
SCHEMA="support_mozilla_com.2013.07.17.schema.sql"
DATA="support_mozilla_com.2013.07.17.data.sql"
SIZE="$(du $DATA | awk '{ print $1 }')K"
DBNAME="kitsune"
{
echo "Dropping/creating database ${DBNAME}" >&2
echo "DROP DATABASE IF EXISTS ${DBNAME};"
echo "CREATE DATABASE ${DBNAME};"
echo "use ${DBNAME};"
echo "Setting speed settings" >&2
echo "SET FOREIGN_KEY_CHECKS = 0;"
echo "SET UNIQUE_CHECKS = 0;"
echo "SET AUTOCOMMIT = 0;"
echo "Loading schema" >&2
cat $SCHEMA
echo "Loading data (this will take a while)" >&2
cat $DATA
echo "Resetting speed settings" >&2
echo "SET FOREIGN_KEY_CHECKS = 1;"
echo "SET UNIQUE_CHECKS = 1;"
echo "COMMIT;"
echo "Done." >&2
} | pv -ps $SIZE | mysql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment