title: using mysqldump with where option and a long argument list in bash script
body: <p>I am trying to dump a subset of a table in MySQL with mysqldump. I have the id values of rows that I want to select from the table, stored in a file. When I use these values as a variable as follows:</p>
  
  <pre><code>ids=`cat ids.csv`
  mysqldump -u root -p db Table --where="id in ($ids)" &gt;&gt; dump.sql
  </code></pre>
  
  <p>I get:</p>
  
  <blockquote>
    <p>x.bash: line x: /usr/bin/mysqldump: Argument list too long</p>
  </blockquote>
  
  <p>I might can try to divide the single line variable $ids (1,2,3,4,..) into shorter lists and call mysqldump in a loop but I am currently not very good with loops in bash scripts.
  Or there might be a better way to solve this issue. </p>
  
  <p>Thanks in advance for any help.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Considering @ajreal's suggestion, 
  If I do </p>
  
  <pre><code>mysql -u root -p -e "select * into outfile ./dump.sql from db.Table where id in ($ids)"
  </code></pre>
  
  <p>I get "Argument list too long" again.</p>
  
  <p>I get the id values from another environment. The database that I run this script against and the database that I get the id values to use within the where clause are in separate environments.
  Additionally, before this step I create the dump file with --ignore-table option, ignoring the "Table" table that I use in the next step. Therefore i would prefer to use mysqldump for that step too. </p>