title: Bash script for update multiple database with multiple file
body: <p>I need to create a script for the updating of multiple database with different files.
  Follows the description of the current process:</p>
  
  <pre><code>show database;
  +--------------------+
  | Database           |
  +--------------------+
  | information_schema |
  | Audi               |
  | Bmw                |
  | Ferrari            |
  | mysql              |
  | performance_schema |
  +--------------------+
  </code></pre>
  
  <p>for each database I have a sql file, like:</p>
  
  <pre><code>update_Audi.sql
  update_Bmw.sql
  update_Ferrari.sql
  </code></pre>
  
  <p>and I use this method:</p>
  
  <pre><code>mysql -uroot -pxxxxx Audi &lt; /path_to_/update_Audi.sql
  mysql -uroot -pxxxxx Bmw &lt; /path_to_/update_Bmw.sql
  mysql -uroot -pxxxxx Ferrari &lt; /path_to_/update_Ferrari.sql
  </code></pre>
  
  <p>this is just an example, but we have over 50 databases for each brand....</p>
  
  <p>sometimes I have a generic file for all database like all_db.sql. And I use this procedure:</p>
  
  <pre><code>mysql -uroot -pxxxxx Audi &lt; /path_to_/all_db.sql
  mysql -uroot -pxxxxx Bmw &lt; /path_to_/all_db.sql
  mysql -uroot -pxxxxx Ferrari &lt; /path_to_/all_db.sql
  </code></pre>
  
  <p>When I want to import more than one file, I need to associate a specifc file "ex audi" to the proper database:</p>
  
  <pre><code>mysql -uroot -pxxxxx Audi &lt; /path_to_/update_Audi.sql
  </code></pre>
  
  <p>How I can automatically select the file "update_Audi.sql" to import it into its database "Audi"?</p>
  
  <p>Now, I need to import the same file into several databases, How may I do it?</p>
  
  <p>I have tried to do it, but I have stopped because I don't know how to continue...
  Here is the incomplete bash script:</p>
  
  <pre><code>#!/bin/bash 
  MyUSER="root"     # USERNAME
  MyPASS="xxxxx"       # PASSWORD
  MyHOST="localhost"          # Hostname
  #Autodetected via which command    
  MYSQL="$(which mysql)"
  #Gethostname                                          
  HOST="$(hostname)"
  #Date
  NOW="$(date +"%d-%m-%Y")"
  
  # Store list of databases
  DBS=""
  #I dont know to do it...
  SINGLE_FILE="path_to_file"
  MULTIPLE_FILE="Multiple file path"
  
  # Exclude these databases
  IGGY="mysql information_schema performance_schema"
  
  
  # Get all database list first
  DBS="$($MYSQL -u$MyUSER -p$MyPASS -h$MyHOST -Bse 'show databases')"
  
  for db in $DBS
  do
      skipdb=-1
      if [ "$IGGY" != "" ];
      then
          for i in $IGGY
          do
                [ "$db" == "$i" ] &amp;&amp; skipdb=1 || :
                done
      fi
  
      if [ "$skipdb" == "-1" ] ; then
  
          #For single File to import
          $MYSQL -u $MyUSER -h $MyHOST -p$MyPASS $db &lt; $SINGLE_FILE
          #For multiple file to import
          $MYSQL -u $MyUSER -h $MyHOST -p$MyPASS $db &lt; $MULTIPLE_FILE
  
      fi
  done
  </code></pre>