It is an easy task to find MySQL variable values:
mysql> show variables where Variable_name = 'version'; +---------------+--------------------+ | Variable_name | Value | +---------------+--------------------+ | version | 5.0.19-Max | +---------------+--------------------+ 1 row in set (0.00 sec)
But is there any syntax that allows to select only column with variable value, like so:
mysql> command_i_want_to_know +--------------------+ | Value | +--------------------+ | 5.0.19-Max | +--------------------+ 1 row in set (0.00 sec)
SET @yourVariableName = yourValue; Let us check the above syntax to create a variable and display the value of created variable.
The user-defined variable enables us to store a value in one statement and later can refer it to another statement. MySQL provides a SET and SELECT statement to declare and initialize a variable.
There are two ways to assign a value to a user-defined variable. You can use either := or = as the assignment operator in the SET statement. For example, the statement assigns number 100 to the variable @counter. The second way to assign a value to a variable is to use the SELECT statement.
-- Syntax to Declare/Set a Global variable SET GLOBAL sort_buffer_size = 500000; SET @@global. sort_buffer_size = 500000; -- Syntax to Declare/Set a Session variable SET sort_buffer_size = 500000; SET SESSION sort_buffer_size = 500000; SET @@sort_buffer_size = 500000; SET @@local.
One more variant -
SELECT @@version;
select variable_value
from information_schema.global_variables
where variable_name = 'version';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With