2015-12-12

MySQL Connector/Java supports connection attributes since version 5.1.25.  This projects useful metadata about the client environment into the database, where MySQL administrators can query PERFORMANCE_SCHEMA tables to remotely survey application deployment environments.  One useful piece of information exposed is the version and vendor of the JVM in use by the client.  This very short blog demonstrates how to get this information from PERFORMANCE_SCHEMA.

The metadata including the Java runtime environment version and vendor can be found in PERFORMANCE_SCHEMA.SESSION_CONNECT_ATTRS table.  Here’s the full contents of that table for a single connection from Connector/Java:

As seen above, both the JRE version and vendor are displayed in separate rows. The following SQL gets just the information we really care about, and makes the output a little bit more tidy:

Visibility into the JRE in use by clients is meaningful information to MySQL administrators. For example, TLSv1.2 is only supported in relatively recent browsers. Knowing which applications are connecting using older Java runtime libraries that don’t support TLSv1.2 is useful for DBAs to know before disabling TLSv1.0 and TLSv1.1.

As a quick note, I found a bug while trying to access JRE information – it turns out that connecting without a default database in the JDBC URL causes the connection attribute information to get lost.  I think most people use a default database, so this is unlikely to affect many people, but I reported it here.

This is handy information for MySQL admins to have access to, and while it’s not exactly earth-shattering, I find myself having to dig into PERFORMANCE_SCHEMA table definitions to remember how to build useful queries.  This blog post is a post-it note for my own future reference, and I hope you may also find it useful.

PlanetMySQL Voting: Vote UP / Vote DOWN

Show more