title: How to get number of rows deleted from mysql in shell script
body: <p>I can't work out how to get the mysql client to return the number of rows deleted to the shell when running a delete. Does anyone know what option will enable this? Or ways around it?</p>
  
  <p>Here's what i'm trying, but i get no output:</p>
  
  <pre><code>#!/bin/bash
  deleted=`mysql mydb -e "delete from mytable where insertedtime &lt; '2010-04-01 00:00:00'"|tail -n 1`
  </code></pre>
  
  <p>I was expecting something like this as the output from mysql:</p>
  
  <pre><code>deleted
  999999
  </code></pre>
  
  <p>Which is why i have the tail -n 1 so i only pick up the count and not the column name.</p>
  
  <p>When running the command by hand (mysql mydb -e "delete from mytable where insertedtime &lt; '2010-04-01 00:00:00'") there is no output. When running the command interactively when running the mysql client i ge the following: </p>
  
  <pre><code>mysql&gt;delete from mytable where insertedtime &lt; '2010-04-01 00:00:00';
  Query OK, 0 rows affected (0.00 sec)
  </code></pre>
  
  <p>I want to get the rows affected count into my shell variable.</p>
  
  <p>Any help would be most appreciated.</p>