mysqllinuxmysqladminmysqladministrator

mysql user last login / access date time


During in a audit task, I am going to delete few mysql users. Before delete I want to check, when the last time these user access the database server. I want to know if we have this information stored in information_schema or mysql databases. If not how can we achieve this?


Solution

  • You can look in the general log for any unsuccessful connection attempts to MySQL however out-of-the-box, MySQL typically does not log successful DB connections. This could become a very, very large log and that activity may quickly overwhelm the I/O subsystem and cause problems for the DB.

    You can setup this sort of logging however it will result in quite a LOT of data! have a look at this post over in the DBA Exchange: https://dba.stackexchange.com/questions/668/audit-logins-on-mysql-database

    If you are using a DB server that is yours and yours alone, you should be able to do this. If you have a DBaaS type thing, multi-tenant DB systems would die logging each connect. This may not be possible?

    You may also find some steps on enabling usertracking in MySQL from the Percona blog: https://www.percona.com/blog/2012/12/28/auditing-login-attempts-in-mysql/