Advertisement
locvfx

automatically import all tables

May 25th, 2016
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.72 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # import-files-mysql.sh
  4. # Descr: Import separate SQL files for a specified database.
  5. # Usage: Run without args for usage info.
  6. # Author: Will Rubel
  7. # Notes:
  8. #  * Script will prompt for password for db access.
  9.  
  10. [ $# -lt 3 ] && echo "Usage: $(basename $0) <DB_HOST> <DB_USER> <DB_NAME> [<DIR>]" && exit 1
  11.  
  12. DB_host=$1
  13. DB_user=$2
  14. DB=$3
  15. DIR=$4
  16.  
  17. DIR=$DIR/*
  18.  
  19.  
  20. echo -n "DB password: "
  21. read -s DB_pass
  22. echo
  23. echo "Importing separate SQL command files for database '$DB' into '$DB'"
  24.  
  25. file_count=0
  26.  
  27.  
  28. for f in $DIR
  29.  
  30. do
  31.     echo "IMPORTING FILE: $f"
  32.  
  33.     gunzip -c $f | mysql -h $DB_host -u $DB_user -p$DB_pass $DB
  34.  
  35.     (( file_count++ ))
  36. done
  37.  
  38. echo "$file_count files importing to database '$DB'"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement