21.1.4 Using the MySQL Enterprise Plugin for Connector/Net

The MySQL Enterprise Plugin for Connector/Net lets you use the Query Analyzer to monitor MySQL queries from any application using Connector/Net, including both standalone and web-based applications. As described in Section 21.3, “Query Analyzer User Interface”, the Query Analyzer can help you locate queries that are inefficient or slow. Tuning such queries helps to shorten load times for web pages, and improves overall system responsiveness and scalability.

Information about the queries is sent directly to the MySQL Enterprise Service Manager. Once you install the MySQL Enterprise Plugin for Connector/Net, query analysis becomes available for your applications without requiring any modification to the application code.

Table 21.7 Query Analyzer Connector/Net Summary

FeatureC/NET
Uses AggregatorNo
Uses ProxyNo
Supports EXPLAINYes

Prerequisites

Installation

Download the MySQL Enterprise Plugin for Connector/Net package. Extract the package using a suitable zip tool, and then place the plugin library, MySql.MonitorPlugin.dll, in the same directory as your compiled application.

Configuration

If the application to profile does not have an app.config application configuration file, then make one.

To enable Query Analyzer functionality, register the trace listeners in the System.Diagnostics section of the app.config file. The following example shows the format of a typical configuration file:


<system.diagnostics>
  <sources>
    <source name="mysql" switchName="SourceSwitch"
    switchType="System.Diagnostics.SourceSwitch">
      <listeners>
        <add name="EMTrace" type="MySql.EMTrace.EMTraceListener, MySql.MonitorPlugin"
                initializeData=""
                Host="SERVERHOST:SERVERPORT"
                PostInterval="POSTINTERVAL"
                UserId="AGENTUSERID"
                Password="AGENTPASSWORD"/>
      </listeners>
    </source>
  </sources>
  <switches>
    
    <add name="SourceSwitch" value="All"/>
  </switches>
</system.diagnostics>

<system.data>

  <DbProviderFactories>
    <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient"
    description=".Net Framework Data Provider for MySQL"
    type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.2.1.0, \
    Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
  </DbProviderFactories>

</system.data>

Within the configuration, set the values of the following parameters:

To get extended information on queries and have that information available through the MySQL Enterprise Monitor User Interface, enable the Connector/Net usage advisor. The extended information identifies potential issues such as a query not using an index, or not accessing all columns from a result set.

To enable the usage advisor, add usage advisor=true to the connection string within your application. Enabling this option also automatically enables logging within Connector/Net. For more information, see Connector/Net Connection String Options Reference.

During execution of the application during development within Visual Studio, a significant amount of output is displayed in the Output window. To view this same trace output when running the application outside Visual Studio, configure an additional listener by adding the following within the system.diagnostics section of your app.config file:


<trace autoflush="false" indentsize="4">
  <listeners>
    <add name="consoleListener" type="System.Diagnostics.ConsoleTraceListener" />
  </listeners>
</trace>

Usage

After you set up MySQL Enterprise Plugin for Connector/Net, you monitor the performance of your .NET applications through the Query Analyzer tab, as described in Section 21.3, “Query Analyzer User Interface”.