HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlModerate

Can you see other users' session variables in MySQL?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
canyouotherseemysqlsessionvariablesusers

Problem

In MySQL, Using SHOW GLOBAL VARIABLES gives the ability to see global variables.
SHOW SESSION VARIABLES are the variable settings for that session.

Is there a way to see the SESSION variables of other active, connected users, from a superuser connection? For example, is there a query or view that would show me which active sessions have variables set differently from the global variables?

Solution

As of MySQL 5.7 the performance_schema can provide this information.


Is there a way to see the SESSION variables of other active, connected users, from a superuser connection ?

You can get these from performance_schema.variables_by_thread.

You will need to know the Thread ID. The ID from SHOW PROCESSLIST is Process ID. Knowing the Process ID you can then look up the Thread ID from performance_schema.threads.


is there a query or view that would show me which active sessions have variables set differently from the global variables?

You sure can.

SELECT VARIABLE_NAME, gv.VARIABLE_VALUE, tv.VARIABLE_VALUE
FROM performance_schema.global_variables gv
  JOIN performance_schema.variables_by_thread tv USING (VARIABLE_NAME)
WHERE gv.VARIABLE_VALUE <> tv.VARIABLE_VALUE
  AND THREAD_ID = ?;

Code Snippets

SELECT VARIABLE_NAME, gv.VARIABLE_VALUE, tv.VARIABLE_VALUE
FROM performance_schema.global_variables gv
  JOIN performance_schema.variables_by_thread tv USING (VARIABLE_NAME)
WHERE gv.VARIABLE_VALUE <> tv.VARIABLE_VALUE
  AND THREAD_ID = ?;

Context

StackExchange Database Administrators Q#65144, answer score: 12

Revisions (0)

No revisions yet.