I'm creating a MYSQL Trigger. I'd like the trigger to record the ip address of the user who initiated the database change.
Is this possible? And if so, how can MySQL get the user's IP Addy?
I'm creating a MYSQL Trigger. I'd like the trigger to record the ip address of the user who initiated the database change.
Is this possible? And if so, how can MySQL get the user's IP Addy?
You cannot get the IP address of the user using MySQL. You do have access to the invoking user via USER(). e.g.
mysql> select USER();
+--------------------+
| USER() |
+--------------------+
| hobodave@localhost |
+--------------------+
1 row in set (0.06 sec)
If you want to know which MySQL user initiated the database change, you can use the USER() function, which will return the invoking user.
However, understand that we're talking about MySQL user, this has nothing to do with the web. For instance, if your application is a web-application, the address will be "localhost" or the name of your server, not the address of the person using your web application. To get their address, you'll have to do so using PHP or any equivalent language.