Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List of users accessing database

I have a MySQL database accessed by a group of my teammates. Is there any command to get the log information of the users who are currently accessing or who have already accessed and logged out?

like image 708
Sayamima Avatar asked Apr 07 '11 02:04

Sayamima


People also ask

How can I get a list of all database users?

We can use the following query to see the list of all user in the database server: mysql> Select user from mysql.

How do I get a list of all SQL Server Logins?

Answer: In SQL Server, there is a catalog view (ie: system view) called sys. sql_logins. You can run a query against this system view that returns all of the Logins that have been created in SQL Server as well as information about these Logins.

How can I tell if someone has access to my database?

HAS_DBACCESS returns 1 if the user has access to the database, 0 if the user has no access to the database, and NULL if the database name is not valid. HAS_DBACCESS returns 0 if the database is offline or suspect. HAS_DBACCESS returns 0 if the database is in single-user mode and the database is in use by another user.

How do I see what user has access to a table?

To determine which users have direct grant access to a table we'll use the DBA_TAB_PRIVS view: SELECT * FROM DBA_TAB_PRIVS; You can check the official documentation for more information about the columns returned from this query, but the critical columns are: GRANTEE is the name of the user with granted access.


1 Answers

Run the following from a mysql tool to view all currently running processes (including sleeping connections):

SHOW PROCESSLIST

Or, you can query the information_schema table to get the same:

select * from information_schema.processlist

To see a history of whom all has logged in, you could configure the general query log to go to a table, by adding the following startup parameter to your mysqld startup "--log-output=TABLE --general-log", then you can query this information out of the general_log table in the mysql schema. Following is the query you could use:

select * from mysql.general_log where command_type = 'Connect';

A word of warning though, this table could get huge. You'll want to periodically clean it out.

like image 148
squawknull Avatar answered Oct 12 '22 10:10

squawknull