12.3 Using the MySQL Enterprise Plugin for Connector/Net

The MySQL Enterprise Plugin for Connector/Net enables you to 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 23.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.

Figure 12.3 Connector Plugin Architecture

Connector Plugin Architecture

Prerequisites

  • You must be using Connector/Net version 6.2.3 or later.

  • The MySQL client application user must have SELECT privileges on the mysql.inventory table. This table contains the server UUID; it is required to report the Query Analyzer data to the MySQL Enterprise Service Manager. Use the GRANT statement. For example:

    mysql> GRANT SELECT on mysql.inventory to 'user'@'localhost' IDENTIFIED BY 'password';
    
  • Your application should already be using the Mysql.data.dll and have been built with the library requirement.

  • If you are using the released builds of Connector/Net, you must include the logging=true option within your connection string.

Installation

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

Configuration

If the application 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>
    <!-- You can set the level at which tracing is to occur -->
    <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:

  • Host

    The hostname and port number, separated by a colon, of the MySQL Enterprise Service Manager that receives the Query Analyzer data.

  • PostInterval

    Query analyzer information is collected and then transmitted (posted) in a batch from your application to the MySQL Enterprise Service Manager. This value specifies the number of seconds between each transmission. Choose this value carefully. Too long and it might take some time for queries to appear in the Query Analyzer.

  • UserId

    The name of a user within MySQL Enterprise Service Manager that has rights to send agent information.

  • Password

    The password of a user within MySQL Enterprise Service Manager that has rights to send agent information.

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 23.3, “Query Analyzer User Interface”.