Skip to content

Instantly share code, notes, and snippets.

@lucassmacedo
Last active May 17, 2016 18:58
Show Gist options
  • Save lucassmacedo/8a9d507425feef607960fc6106c5fbda to your computer and use it in GitHub Desktop.
Save lucassmacedo/8a9d507425feef607960fc6106c5fbda to your computer and use it in GitHub Desktop.
Export all databases on mysql
#!/bin/bash
#Por : Lucas Macedo
#se você usar apenas usuário sem senha, use este linha abaixo
usuarioesenha="-u root -proot"
#pasta para exportação do banco
pasta_backup="/Users/Lucas/backup_banco"
#define o path do mysql, se estiver global deixe apenas "mysql" ex: C:\wamp\bin\mysql\mysql5.6.12\bin\mysql
_mysql="/Applications/MAMP/Library/bin/mysql"
#define o path do mysqldump, se estiver global deixe apenas "mysqldump" ex: C:\wamp\bin\mysql\mysql5.6.12\bin\mysqldump
_mysqldump="/Applications/MAMP/Library/bin/mysqldump"
databases=(`$_mysql -e "show databases" ${usuarioesenha}`)
if [ -d "$pasta_backup" ];
then
#MYSQL DUMP
for database in "${databases[@]}"
do
if [ $database != "Database" ] && [ $database != "information_schema" ] && [ $database != "performance_schema" ]; then
echo "Exportando banco: $database"
$_mysqldump ${usuarioesenha} ${database} > "$pasta_backup/$database.sql"
fi
done
else
echo "Caminho : $pasta_backup não encontrado"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment