3.1.1 Using the MySQL Enterprise Plugin for Connector/J

The MySQL Enterprise Plugin for Connector/J lets you use the Query Analyzer to monitor MySQL queries from any application using the Connector/J JDBC driver. As described in Section 3.2, “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/J, query analysis becomes available for your applications without requiring any modification to the application code.

Table 3.2 Query Analyzer Connector/J Summary

Uses AggregatorNo
Uses ProxyNo
Supports EXPLAINYes


  1. MySQL Connector/J version 5.1.12 or later.

  2. JDK-1.5.0 or later.

  3. MySQL Enterprise Service Manager version 2.2 or later.

  4. 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';
  5. Apache Commons logging in the CLASSPATH of the application being analyzed. If you are not already using Commons Logging, modify the application's CLASSPATH as described in the following section to point to the JAR file bundled with the MySQL Enterprise Monitor product.


Place the JAR file lib/c-java-mysql-enterprise-plugin-version.jar in the application's CLASSPATH where it is visible to the version of MySQL Connector/J in use. Ideally, use the same location as MySQL Connector/J's JAR file, or in a parent classloader to that JAR file's location.

If the application being analyzed does not have Apache Commons Logging in the CLASSPATH, install the file lib/required/commons-logging-1.1.1.jar in the application's CLASSPATH as well. If no other component in your application uses Apache Commons Logging, install it in the same place where the Query Analyzer plugin was installed.

There is static shutdown() method on com.mysql.etools.jdbc.StatementPerformanceCounters, which can be used to cleanly shutdown the query analysis plugin when the application is going to be shutdown.

If the application in question is deployed in a J(2)EE application server, there is an included ContextListener distributed with the plugin which will call this method when the application's context is shutdown (or reloaded). Application Servers which support @WebListener (such as JEE6 and above) do not need to do any extra configuration, but users with older Application Servers need to add the following line to their application's web.xml file:


The Connector/J plugin prior to version 1.0.81 can use a workaround by placing the plugin in the shared library loader of their Application Server, rather than in the WEB-INF/lib directory.


Once the required JAR files are deployed, modify the connection URL for JDBC to use and configure the Query Analyzer plugin. Add the following properties and their corresponding values to the URL that is used by the application you are monitoring.

For more information on Connector/J properties, see Connector/J (JDBC) Reference.

Table 3.3 MySQL Monitor Plugin for Connector/J Options

To use SSL to communicate query information to the MySQL Enterprise Service Manager, configure the following properties. Out of the box, the plugin is configured to work with the self-signed certificates that ship with the MySQL Enterprise Monitor. Therefore, it provides confidentiality for the information that is sent by the plugin if the service manager URL starts with https://. However, as configured, the plugin does not prevent man-in-the-middle attacks, nor does it support client-side certificates for authentication. To enable these features, change the values of the following parameters:

Table 3.4 MySQL Monitor Plugin for Connector/J SSL Options

For example, to configure a Connector/J to communicate with the MySQL Enterprise Service Manager localhost, on port 18080, using the agent username agent, and password PASSWORD, you would add the following options to your connection string (but define the option on a single line):


Remember that you must also add the application-specific options to the JDBC URL. For example, the following fragment connects to the MySQL database test on localhost, using the user and password of mysqltest, while also collecting query data and sending it to the MySQL Enterprise Service Manager on localhost:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

Connection conn = null;
try {
    conn =
       DriverManager.getConnection("jdbc:mysql://localhost/test?" +
           "user=mysqltest" + 
           "&password=mysqltest" +
           "&statementInterceptors=com.mysql.etools.jdbc.StatementPerformanceCounters" +
           "&serviceManagerUrl=http://localhost:18080/" + 
           "&serviceManagerUser=agent" + 

    // Do something with the Connection

} catch (SQLException ex) {
    // handle any errors

If a DataSource is in use (typically when using Glassfish, Weblogic, or Websphere), these properties must be passed as part of the URL property, they cannot be added to the DataSource configuration itself.

If an alternate logging system has not been selected for Connector/J, it is recommended that Connector/J's log factory is configured to use something other than the standard logger by adding the following property to the URL or DataSource:

Further configuration of the plugin is done via the Enterprise Service Manager's user interface, using the Query Analyzer tab. From here, the capture of query performance data for a given MySQL instance that the plugin is being with can be enabled or disabled. Further, the level of detail that is captured; summary, examples (with source code locations) and EXPLAIN plans can be configured as well.

The Query Analyzer plugin checks the configuration once each minute (while it is reporting data it has collected), thus configuration changes are not immediate.


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


Be aware of the following while using the MySQL Enterprise Plugin for Connector/J: