Bug #2682 When MySQL user last logged into MySQL server.
Submitted: 9 Feb 2004 5:14 Modified: 28 Nov 2005 10:09
Reporter: Alexandr Gorlov Email Updates:
Status: Verified Impact on me:
Category:MySQL Server: Logging Severity:S4 (Feature request)
Version: OS:Any
Assigned to: CPU Architecture:Any

[9 Feb 2004 5:14] Alexandr Gorlov
I think many DBA need to know when the user last connected (or loged in) to MySQL server.

PS: I've opened documentation on MySQL-site, but i didn't find such feature.

Thank You!

How to repeat:

Suggested fix:
Posible to add field into user table: lastlog or so in DATETIME format.
[28 Nov 2005 10:09] Valeriy Kravchuk
Thank you for a useful feature request. You can get this information from the general query log, but it is not good idea to enable it in real production environment. So, additional column for mysql.user table or additional audit log (there are some plans to add something alike already) will be really useful.
[10 Nov 2009 21:23] Sheeri Cabral
I'll add my vote for this feature....also, note that it's scheduled for version 7.0 in the worklog:

[13 Jan 2018 18:53] Daniël van Eeden
Duplicate of this bug:
Bug #74880 	Record last login timestamp per user
[13 Jan 2018 19:50] Daniël van Eeden
This can be simulated with:

And then:
CREATE TABLE last_login (user varchar(255) primary key , last_login timestamp);

To test:
create user 'myuser'@'localhost' identified by 'mypass';
grant insert,select,update on test.last_login to 'myuser'@'localhost';

The problems with this are:
- Every user needs access to the last_login table
- This doesn't work for users with SUPER
- Users can modify their last login time. A ON UPDATE trigger or using a stored procedure might fix that.

Another option would be to write a plugin:
- An audit plugin ( https://dev.mysql.com/doc/refman/5.7/en/writing-audit-plugins.html )

But then storing that data in a regular table of information_schema would be difficult from the plugin
Writing to a file or sending to something like graphite might work.