Created
October 6, 2011 14:23
-
-
Save squiter/1267515 to your computer and use it in GitHub Desktop.
Import MySQL dump to a database using parameters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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