Skip to content

Instantly share code, notes, and snippets.

@squiter
Created October 6, 2011 14:23
Show Gist options
  • Save squiter/1267515 to your computer and use it in GitHub Desktop.
Save squiter/1267515 to your computer and use it in GitHub Desktop.
Import MySQL dump to a database using parameters
#!/bin/bash
##################################################
#### Script para importar dumps de MySQL #########
#### #########
#### Instruções: #########
#### Sempre passar os parametros #########
#### -u Nome de usuário #########
#### -h Hostname #########
#### -d Nome do Banco #########
#### -f Caminho completo do SQL #########
#### -p Senha (Opcional) #########
#### #########
##################################################
# Configurações
# Onde está seu MySQL?
MySQL="/opt/local/bin/mysql5"
# Não precisa mexer daqui pra baixo ;)
while getopts u:p:h:d:f: OPCAO; do
case "${OPCAO}" in
u) MyUser="${OPTARG}" ;;
p) MyPass="${OPTARG}" ;;
h) MyHost="${OPTARG}" ;;
d) MyDb="${OPTARG}" ;;
f) SQLFile="${OPTARG}" ;;
esac
done
HavePass=$(echo ${#MyPass})
if [ $HavePass -lt 1 ]; then
$MySQL -h $MyHost -u$MyUser $MyDb < $SQLFile
else
$MySQL -h $MyHost -u$MyUser -p$MyPass $MyDb < $SQLFile
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment