title: How to catch SQL statements within a MySQL database?
body: <p>Simply said I have to write an application to synchronise several database tables. Because of the requirements the changes should be put into a queue (in form of a SQL statement) and here lies the problem: I'm not able to change the existing application which uses the database to add the executed query directly into the queue. Therefore I need to catch all data changing SQL queries of specific tables (> 20 tables) in the database.</p>
  
  <p>I though about the following solutions:</p>
  
  <ul>
  <li>To catch directly the MySQL query with triggers like it is described <a href="https://dba.stackexchange.com/questions/8108/can-a-trigger-access-the-query-string">Can a trigger access the query string</a> (best answer for this case I could find!), but I couldn't get the query that actives the trigger - only the query that I used within it.</li>
  <li>To active the General Query Log. But I read about heavy performance considerations and so it isn't an arguable solution, because it would log even the tables I don't need (> 120 tables) and a lot of simple queries run on the database.</li>
  <li>To use a history table filled by trigger. With this I wouldn't save the SQL statement of the queries with this solution (which would slow down my current concept of synchronisation), but it would be possible to realise.</li>
  </ul>
  
  <p>Does someone know any other solution or how I could do the impossible by accessing the query within a trigger? </p>
  
  <p>I'm grateful about any suggestion!</p>
  
  <p>Related questions:<br>
  <a href="https://dba.stackexchange.com/questions/8108/can-a-trigger-access-the-query-string">Can a trigger access the query string</a> <br>
  <a href="https://dba.stackexchange.com/questions/7985/log-mysql-db-changing-queries-and-users/8085#8085">Log mysql db changing queries and users</a></p>