How to list all variables initialized by SET operator in MySQL?


To list all variables initialized by SET operator, the syntax is as follows −

select * from performance_schema.user_variables_by_thread;

Here is the query to set the variable −

mysql> set @FirstName='John';
Query OK, 0 rows affected (0.00 sec)
mysql> set @LastName='Doe';
Query OK, 0 rows affected (0.00 sec)

Here is the query to display the list of all variables initialized by SET operator. This list includes the variables set above −

mysql> select * from performance_schema.user_variables_by_thread;

This will produce the following output −

+-----------+---------------+----------------+
| THREAD_ID | VARIABLE_NAME | VARIABLE_VALUE |
+-----------+---------------+----------------+
|       120 | TotalAmount   |           5000 |
|       120 | FirstName     |           John |
|       120 | lName         |          Smith |
|       120 | fName         |           Adam |
|       120 | LastName      |            Doe |
+-----------+---------------+----------------+
5 rows in set (0.00 sec)

Updated on: 26-Dec-2019

203 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements