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!
Asked
Active
Viewed 662 times
1 Answers
0
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());

Jean-François Savard
- 20,626
- 7
- 49
- 76
-
Thanks, Mr Savard! However, I cannot know where to insert the CURRENT_USER() function. The addition of the 'user' column to the history table has been set, but I am at a loss as to what to do next... – kenkenhimself Mar 05 '15 at 15:48
-
Thanks again! I tried that just now and I get this error: Error Code: 1235. This version of MySQL doesn't yet support 'multiple triggers with the same action time and event for one table' – kenkenhimself Mar 05 '15 at 16:07
-
egad! now i have a working table with the user column. thanks a lot, mate! – kenkenhimself Mar 05 '15 at 16:17
-
@Savard When CURRENT_USER() is added the database will update as root@localhost. Not the system's logged in user name. – dilk Jun 11 '21 at 04:26