Skip to content

Instantly share code, notes, and snippets.

@daogurtsov
Created May 27, 2012 15:08
Show Gist options
  • Save daogurtsov/2814626 to your computer and use it in GitHub Desktop.
Save daogurtsov/2814626 to your computer and use it in GitHub Desktop.
import list of databases to mysql
#!/bin/sh
#Import list of databases to MySQL
#Start vars declaration
importPath=dbes
dbList=domains.txt
importLog=import_log.txt
#End vars declaration
if [ -d "$importPath" -a -f "$dbList" ]; then
if [ -f "$importLog" ]; then
rm "$importLog"
fi
touch "$importLog"
while read db_file_name db_name db_user db_pass db_host
do
pathToDB="$importPath"/"$db_file_name"
if [ -f "$pathToDB" ]; then
mysql -h "$db_host" -u "$db_user" --password="$db_pass" "$db_name" < "$pathToDB"
date=`date`
echo "$pathToDB"
echo "$db_file_name $date" >> "$importLog"
else
echo "$pathToDB"
echo "$pathToDB -doesn't exist" >> "$importPath"
fi
done < "$dbList"
cat "$importLog"
echo "==============="
wc -l "$importLog"
else
echo "Check import path and dblist file"
fi
echo "=============="
echo "IMPORT FINISHED"
@daogurtsov
Copy link
Author

dblist.txt format example:
db_file_name db_name user password host
test2 test2 root win7 localhost
test3 test3 root win7 localhost
test4 test4 root win7 localhost
test5 test5 root win7 localhost

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment