Search code examples
mysqluser-tracking

Adding user name to a table in MySQL


I am new to MySQL and I have created a table which I named 'adb_history' that keeps track of the changes made from the main table 'adb'. It was implemented successfully thanks to the creation of triggers (update, insert, delete). The idea is that there will be two or more users (admins) that can manipulate the table. So I am thinking of creating a new column to also track/add the user (that is, log the user name from the server) that made the changes/updates. Can this be done? My workbench version is 5.6. Thanks for the help!


Solution

  • Yes this can be done, simply insert CURRENT_USER().

    See documentation for more information on the function.


    Edit : To answer your comment, it would look something like this :

    INSERT INTO adb_history VALUES (value1, value2, valueN, CURRENT_USER());