Practical P_S: Find Client JRE Version Using SQL

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:

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.

I very much agree – I’ve been wanting to see P_S connection attributes recorded in logs as well. I’m working with the Docs team and the other connectors teams to standardize and document the attributes exposed by each.