Robin Rodricks
Robin Rodricks

Reputation: 113976

How to get the value of a MySQL VARIABLES var?

I need to fetch a scalar value of the MySQL VARIABLE "version". Currently running this:

SHOW VARIABLES WHERE Variable_name="version"

Is giving me a table like:

Variable_name    Value
-------------    -----------
version          5.5.28-log

How do I just get the Value cell?

Upvotes: 1

Views: 96

Answers (3)

Asaph
Asaph

Reputation: 162801

You can use the built-in version() function.

select version();

Upvotes: 0

D Mac
D Mac

Reputation: 3809

set @x = select @@version;

That will set the user variable @x with the current version.

If you want it in a straight select, use

select @@version;

This generalizes - most system variables are available using the @@ syntax.

Upvotes: 1

Robin Rodricks
Robin Rodricks

Reputation: 113976

Okay, I found out how:

 select variable_value 
 from information_schema.global_variables
 where variable_name = 'version';

Upvotes: 0

Related Questions