Answers.Body: <p>If you want to see <em>everything</em>, you can enable MySQL logging as follows (don't do this on production!): </p>
  
  <ol>
  <li><p>From the mysql console (or within an application like <a href="https://www.mysql.com/products/workbench/">MySQL Workbench</a>), run: </p>
  
  <pre><code>SET global general_log = 1;
  SET global log_output = 'table';
  </code></pre></li>
  <li><p>Look at all queries run within the last 15 seconds </p>
  
  <pre><code>select * 
  from mysql.general_log 
  where 
    command_type = 'Query' and 
    event_time &gt; now() - interval 15 second;
  </code></pre></li>
  <li><p>Try to find queries on the civicrm_contact table </p>
  
  <pre><code>select * from mysql.general_log 
  where 
    argument like '%civicrm_contact%' and 
    argument not like '%general_log%' 
  order by event_time desc;
  </code></pre></li>
  <li><p>Clear the log </p>
  
  <pre><code>truncate table mysql.general_log; 
  </code></pre></li>
  <li><p>Turn off logging </p>
  
  <pre><code>SET global general_log = 0; 
  </code></pre></li>
  </ol>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-23T13:27:44.847Z
Answers.LastActivityDate: 2015-04-23T13:27:44.847Z
Answers.UserDisplayName: Sean
Answers.Body: <p>Try setting:</p>
  
  <p>define('CIVICRM_DAO_DEBUG', 1);</p>
  
  <p>in your civicrm.settings.php file, this might work based on a quick glance at the code.</p>
  
  <p>The output will appear onscreen and in the CiviCRM log file (eg <code>sites/default/files/civicrm/ConfigAndLog/CiviCRM*log</code> or <code>media/civicrm/ConfigAndLog/CiviCRM*log</code> or <code>wp-content/plugins/files/civicrm/ConfigAndLog/CiviCRM*log</code>)</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-23T13:03:21.100Z
Answers.LastActivityDate: 2015-05-08T16:32:44.733Z
Answers.LastEditDate: 2015-05-08T16:32:44.733Z
Answers.UserDisplayName: Donald Lobo
Answers.Body: <p>If your page happens to be a report, you can install the <a href="http://wiki.civicrm.org/confluence/display/CRMDOC/Extended+Reports+Extension" rel="nofollow">Extended Reports</a> extension which will display the full sql query being run.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-31T19:17:27.343Z
Answers.LastActivityDate: 2015-05-31T19:17:27.343Z
Answers.UserDisplayName: Coleman
Answers.Body: <p>I am not sure wether such a functionality exist in CiviCRM but something wich might be worth a look at is the logfiles</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-23T12:57:50.003Z
Answers.LastActivityDate: 2015-04-23T12:57:50.003Z
Answers.UserDisplayName: Jaap Jansma - CiviCooP
Body: <p>When debugging CiviCRM pages, is there a native way to emit the SQL statements being run, eg on a Search page? I'm looking for something easier than finding the code for the page and putting in a debug_var kind of statement. I'd prefer to not have to rely on a Drupal module like cTools, since we work with other CMSes frequently these days.</p>
  
Tags: <debugging><mysql>
Title: What is the easiest way to see the MySQL queries run by a CiviCRM page?
ThreadText: # What is the easiest way to see the MySQL queries run by a CiviCRM page?
  
  (Asked by: username_0 on 2015-04-21)
  
  When debugging CiviCRM pages, is there a native way to emit the SQL statements being run, eg on a Search page? I'm looking for something easier than finding the code for the page and putting in a debug\_var kind of statement. I'd prefer to not have to rely on a Drupal module like cTools, since we work with other CMSes frequently these days.
  
  **Tags:** debugging, mysql
  
  
  ---
  
  ## 4 answers
  
  ### Answer by username_1 on 2015-04-23. Score: 10 | Accepted answer
  
  If you want to see *everything*, you can enable MySQL logging as follows (don't do this on production!):
  
  1. From the mysql console (or within an application like [MySQL Workbench](https://www.mysql.com/products/workbench/)), run:
  
     ```
     SET global general_log = 1;
     SET global log_output = 'table';
  
     ```
  2. Look at all queries run within the last 15 seconds
  
     ```
     select * 
     from mysql.general_log 
     where 
       command_type = 'Query' and 
       event_time > now() - interval 15 second;
  
     ```
  3. Try to find queries on the civicrm\_contact table
  
     ```
     select * from mysql.general_log 
     where 
       argument like '%civicrm_contact%' and 
       argument not like '%general_log%' 
     order by event_time desc;
  
     ```
  4. Clear the log
  
     ```
     truncate table mysql.general_log; 
  
     ```
  5. Turn off logging
  
     ```
     SET global general_log = 0; 
  
     ```
  
  
  ---
  
  ### Answer by username_2 on 2015-04-23. Score: 9
  
  Try setting:
  
  define('CIVICRM\_DAO\_DEBUG', 1);
  
  in your civicrm.settings.php file, this might work based on a quick glance at the code.
  
  The output will appear onscreen and in the CiviCRM log file (eg `sites/default/files/civicrm/ConfigAndLog/CiviCRM*log` or `media/civicrm/ConfigAndLog/CiviCRM*log` or `wp-content/plugins/files/civicrm/ConfigAndLog/CiviCRM*log`)
  
  
  ---
  
  ### Answer by username_3 on 2015-05-31. Score: 3
  
  If your page happens to be a report, you can install the [Extended Reports](http://wiki.civicrm.org/confluence/display/CRMDOC/Extended+Reports+Extension) extension which will display the full sql query being run.
  
  
  ---
  
  ### Answer by username_4 on 2015-04-23. Score: 1
  
  I am not sure wether such a functionality exist in CiviCRM but something wich might be worth a look at is the logfiles
  
  
  ---
  
  