Database Reference
In-Depth Information
Statement
Information produced by statement
Current user as given by client when connecting
SELECT USER()
User used for checking client privileges
SELECT CURRENT_USER()
Server global or session status indicators
SHOW [GLOBAL|SESSION] STATUS
Server global or status configuration variables
SHOW [GLOBAL|SESSION] VARIABLES
To obtain the information provided by any statement in the table, execute it and process
its result set. For example, SELECT DATABASE() returns the name of the default database
or NULL if no database has been selected. The following Ruby code uses the statement
to present a status display containing information about the current session:
db = dbh . select_one ( "SELECT DATABASE()" ) [ 0 ]
puts "Default database: " + ( db . nil? ? "(no database selected)" : db )
A given API might provide alternatives to executing SQL statements to access these
types of information. For example, JDBC has several database-independent methods
for obtaining server metadata. Use your connection object to obtain the database met‐
adata, then invoke the appropriate methods to get the information in which you're
interested. 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 ());
// this is similar to SELECT USER() but doesn't include the hostname
System . out . println ( "Username: " + md . getUserName ());
See Also
For more discussion about the use of SHOW (and INFORMATION_SCHEMA ) in the context
of server monitoring, see Recipe 22.6 .
10.9. Writing Applications That Adapt to the MySQL
Server Version
Problem
You want to use a given feature that is available only as of a particular version of MySQL.
Solution
Ask the server for its version number. If the server is too old to support a given feature,
maybe you can fall back to a workaround, if one exists.
 
Search WWH ::




Custom Search