Skip to Main Content
MySQL Cookbook
book

MySQL Cookbook

by Paul DuBois
October 2002
Intermediate to advanced content levelIntermediate to advanced
1024 pages
27h 26m
English
O'Reilly Media, Inc.
Content preview from MySQL Cookbook

Getting Server Metadata

Problem

You want to the MySQL server to tell you about itself.

Solution

Several SELECT and SHOW statements return information about the server.

Discussion

MySQL offers several SQL statements that provide you with information about the server itself and about your current client connection. A few that you may find useful are listed here. To obtain the information provided by any of them, issue the query, then process the result set to retrieve the query output. Both SHOW statements allow a LIKE 'pattern' clause for limiting the results only to those rows matching the pattern.

Statement

Information produced by statement

SELECT VERSION( )

Server version string

SELECT DATABASE( )

Current database name (empty if none)

SELECT USER( )

Current username

SHOW STATUS

Server status indicators

SHOW VARIABLES

Server configuration variables

These queries are all MySQL-specific. If you’re working in Java, JDBC provides several database-independent methods for obtaining server metadata, some of which provide the same information as some of the preceding statements. Use your connection object to obtain the database metadata, then invoke the appropriate methods to get the information in which you’re interested. You should consult a JDBC reference for a complete list, but here are a few representative examples:

DatabaseMetaData md = conn.getMetaData ( ); // can also get this with SELECT VERSION( ) System.out.println ("Product version: " + md.getDatabaseProductVersion ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

MySQL Reference Manual

MySQL Reference Manual

Michael Widenius, David Axmark, Kaj Arno
High Performance MySQL

High Performance MySQL

Jeremy D. Zawodny, Derek J. Balling
MySQL Stored Procedure Programming

MySQL Stored Procedure Programming

Guy Harrison, Steven Feuerstein

Publisher Resources

ISBN: 0596001452Catalog PageErrata