With MySQL 5.1 you can store the general query log in a table. But what if you don't want to log every single statement but only the users logging in and the hosts they're coming from? There exists in fact a very simple solution that even works with MySQL 5.0 and (with some changes) with earlier versions.
The idea is to use the init_connect server variable as a hook to install a logging
routine. The init_connect variable holds SQL
statements to be executed for each client that connects (except
for SUPER users).
We need to create a database and a table first to hold our
connection log. I don't really recommend to use the
mysql database for this as we don't know what might
be added in there by future …