title: How to execute a MySQL command from a shell script?
body: <p>How can I execute an SQL command through a shell script so that I can make it automated?</p>
  
  <p>I want to restore data I have collected in a SQL file using a shell script. I want to connect to a server and restore data. The command works when executed separately via SSH command line.</p>
  
  <p>This is the command I use:</p>
  
  <pre><code>mysql -h "server-name" -u root "password" "database-name" &lt; "filename.sql"
  </code></pre>
  
  <p>This is the shell script code that creates the file <code>ds_fbids.sql</code> and pipes it into mysql.</p>
  
  <pre><code>perl fb_apps_frm_fb.pl
  perl fb_new_spider.pl ds_fbids.txt ds_fbids.sql
  mysql -h dbservername -u username -ppassword dbname &lt; ds_fbids.sql
  </code></pre>
  
  <p>What is the correct way to do this?</p>