title: grant select for temporary table in MySQL
body: <p>I have a MySQL DB with a user that has access only a few tables. This user has been granted <code>CREATE TEMPORARY TABLES</code> for this database and by watching the query logs, I can see them create a temporary table and then fail while trying to select from it. Doing <code>GRANT SELECT ON TABLE 'db'.'tmp_tbl' TO 'user'@'localhost';</code> doesn't work as the table doesn't exist at that point.</p>
  
  <p><a href="http://dev.mysql.com/doc/refman/5.1/en/privileges-provided.html#priv_usage" rel="nofollow noreferrer">The user comments on this page</a> suggest a hack to do this but I would have expected there to be a nicer way.</p>
  
  <hr>
  
  <p>The code that uses this is sorta like this:</p>
  
  <pre><code>CREATE TEMPORARY TABLE t1 SELECT id FROM real1 LIMIT 10;
  CREATE TEMPORARY TABLE t2 SELECT id FROM real2 LIMIT 10;
  
  SELECT * FROM t1;
  SELECT * FROM t2;
  SELECT * FROM t1 JOIN t2 JOIN real3 AS r ON t1.id = r.a AND t2.id = r.b;
  </code></pre>
  
  <p>In this case, the whole point is that the data (or at least some of it) is live.<br>
  I need the results from the first two queries and the values for the join in the third to be the same so using sub queries won't work.</p>