title: How can I get the columns / tables that a query is using during execution MySQL?
body: <p>I have a program that allows users to run custom queries against a number of databases. The program uses the .net connector for MySQL, which creates a connection, command and dataAdapter objects.</p>
  <p>The objective is to get all of the tables / columns that the query is hitting. I know I could parse out the query to get these, but figured there must be an easier way using the connector.</p>
  <p>I would also be interested in a solution that uses a query of some sort? Explain does not do it.</p>
  <p>Example:
  Table1</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th style="text-align: left;">col1</th>
  <th style="text-align: center;">col2</th>
  <th style="text-align: center;">col3</th>
  <th style="text-align: right;">col4</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td style="text-align: left;">test1</td>
  <td style="text-align: center;">tes2</td>
  <td style="text-align: center;">test3</td>
  <td style="text-align: right;">test4</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>Query:</p>
  <pre><code>Select col1 as 'name', col2 as 'first' from Table1;
  </code></pre>
  <p>I am wanting to get an array of columns (not alias) that were used, in this case -&gt; col1, col2. I have looked thru a lot of the docs and couldn't find anything like this. I am assuming there must be a metadata cache somewhere in the connection objects.</p>
  <p>Connector Setup (Powershell):</p>
  <pre><code>$ConnectionString = &quot;server=&quot; + $MySQLHost + &quot;;port=$Mysqlport;uid=&quot; + $Mysqluser + &quot;;pwd=&quot; + $Mysqlpass + &quot;;database=&quot; + $Database + &quot;;allow zero datetime=true;&quot;
  
  [void][System.Reflection.Assembly]::LoadWithPartialName(&quot;MySql.Data&quot;)
  $Connection = New-Object MySql.Data.MySqlClient.MySqlConnection
  $Connection.ConnectionString = $ConnectionString
  $Connection.Open()        
  $Command = New-Object MySql.Data.MySqlClient.MySqlCommand($Query, $Connection)
  $command.CommandTimeout = 7200;       
  $DataAdapter = New-Object MySql.Data.MySqlClient.MySqlDataAdapter($Command)
  $DataSet = New-Object System.Data.DataSet
  $RecordCount = $dataAdapter.FillAsync($dataSet, &quot;data&quot;)
  $results = $DataSet.Tables[0]
  </code></pre>